by running following script in sh , ./ mode different result on ubuntu
#!/bin/bash x=80 z=90 let "a=$x+$z" echo $a result:
sh mode gives me "blank" output, while ./ mode yields 170.
any explanation?
shell selection via invocation method
./mode honors shebang, specifies script invoked bash. contrast, sh mode explicitly uses sh instead, ignoring shebang. (. mode doesn't run new shell @ all, executes commands in script inside same shell you're using interactively).
why shell selection matters
let bash extension compatibility pre-posix shells.
on platform (such ubuntu) /bin/sh implemented ash derivative, little functionality not specified in posix sh standard available.
to perform arithmetic in manner compatible posix-compliant shells (from initial 1992 publication of posix sh standard), use following syntax:
a=$(( x + z ))
Comments
Post a Comment