Which is best way to use the variable in shell script -


i using global variable install_dir='/tmp' , calling function use variable in shell script

which correct method following use variable?

method 1:-

install_dir='/tmp'  install_app() {   echo "application path - $install_dir"  }  install_app 

method 2:-

install_dir='/tmp'  install_app() {  app=$1  echo "application path - $app" }  install_app $install_dir 

if want use variable in multiple places with in same script, first approach better.

but if variable used in different scripts , have export (export make environment variable) in first script before using in second script. refer link exporting 1 script other.

pass variables 1 shellscript another?

for different scripts, use one-dot (.) run . ./myscript.sh, execute within same scope.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -