Thursday, April 21, 2022

Bash/bc

 y=1.0

y=`echo 'y +0.5'|bc -l`

should set y to 1.5.  Right?  $y is not recognized by bc.  y seems to stay 0

2 comments:

  1. Bash variable substitution doesn't happen in '-quoted strings.

    Use:

    y=1.0

    y=`echo "$y +0.5"|bc -l`

    ReplyDelete
  2. This resulted in 1.5 for me:

    y=1.0; y=$(echo "$y+0.5" | bc -l ); echo $y

    ReplyDelete