[Techtalk] weirdness piping to a variable

Peggy Russell prusselltechgroup at gmail.com
Fri Oct 18 07:07:55 UTC 2013


Miriam,

Just one more thing (I promise :-)). I just knew this should work.
Yeh!
 
In Bash 4.2, there is a new option called lastpipe. If set, the
last command is not done in a subshell. So your pipeline command
would work without the (). You need to turn job control off though.

set +m; shopt -s lastpipe; echo 'quick brown fox' |
                           cut -d' ' -f2 | 
                           read a; echo $a

Please ignore the following if you already know:

Bash version info 
1) bash --version
2) bash variable BASH_VERSINFO

   A) declare -p BASH_VERSINFO    # nice for quick debugging
   B) if [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -eq 2 ]]; then 
        echo okay; fi

Just a quick tip. Bash has a builtin command, 'help'. Type 'help' and 
you'll see all the quick help you can get. So rather than wading through
the bash manpage for say, the test or set options, type:
'help test' or 'help set'.

Hope this helped.
Peggy Russell


More information about the Techtalk mailing list