Fix pipe/&& precedence for some bash versions
DrVanScott opened this issue · 2 comments
DrVanScott commented
The fix introduced by c96e44a does not work for me. I use bash "4.3.11(1)-release (x86_64-pc-linux-gnu)" on Ubuntu 14.04. The test function
fc_check () {
echo history:
history | tail -3
echo fc check
fc -ln -1
fc -ln -1 | head -1
(fc -ln -1)
(fc -ln -1 | head -1)
echo $(fc -ln -1)
echo $(fc -ln -1 | head -1)
}
produces the following output
history:
552 echo c2
553 echo c3
554 fc_check
fc check
echo c3
echo c3
echo c3
echo c3
echo c3
fc_check
The last two lines are quite surprising. My fix for this strange behaviour looks like this:
--- composure.sh_upstream 2014-11-20 00:27:16.726785858 +0100
+++ composure.sh 2014-11-20 00:28:57.223999557 +0100
@@ -284,7 +284,7 @@
if [ -z "$num" ]; then
typeset lines=1
# some versions of 'fix command, fc' need corrective lenses...
- (fc -ln -1 | grep -q draft) && lines=2
+ lines=$(fc -ln -1 | grep -q draft && echo 2 || echo 1)
# parse last command from fc output
cmd=$(fc -ln -$lines | head -1 | sed 's/^[[:blank:]]*//')
else
DrVanScott commented
This fix also works on cygwin's bash, version 4.1.17(9)-release (i686-pc-cygwin)
erichs commented
Thank you for bringing this to my attention! I've been pondering how to properly fix the fc discrepancies across systems. I'll take this into consideration!