Sunday, February 2, 2014

Here strings, three less-than-signs

something i just learned about: the here string, rather than echo pipe to command, it is quicker.


flatmac:~ peter$ a="london 43 smog cafes thames uk"
flatmac:~ peter$ read City Value Bad Good Positive Country <<< $a
flatmac:~ peter$ echo $City
london
flatmac:~ peter$ echo $Good
cafes
flatmac:~ peter$ echo $Country
uk


...or if the delimiter is different, this also works though I need to find out how the IFS assignment and read command work together.
flatmac:record peter$ a="london|43|smog|nice shops|river thames|uk"
flatmac:record peter$ IFS='|' read City Value Bad Good Positive Country <<< "$a"
flatmac:record peter$ echo $Positive
river thames
flatmac:record peter$ echo $City
london



No comments:

Post a Comment