linux - Why doesn't "let" work with "sh myscript" on Ubuntu, when it does with "./myscript"? -


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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -