bash - Another way to use a variable readed and passed as argument inside a function -


the script works there way same result without using "tmp" varaible ?

thanks

function ask_version () { while true ;  echo -e "give version of" $1 local tmp=$2 read -r tmp    if [[ ! $tmp =~ ^[0-9]$ ]] ;      echo -e "please respect number format"   elif [[ $tmp -ne $t ]] ;    echo -e "it not true number"   else     return 0   fi done }  ask_version "app1" "app1version" ask_version "app2" "app2version" 

here's functional version of think you're after:

function ask_version () { while true ;  echo -e "give version of $1"  read -r    if [[ ! $reply =~ ^[0-9]$ ]] ;      echo -e "please respect number format"   elif [[ $reply -ne $2 ]] ;    echo -e "it not true number"   else     return 0   fi done }  ask_version "app1" 5 ask_version "app2" 6 

it not use tmp variable; instead, relies on read's default variable reply, , compares function's second parameter $2, pass in actual numbers instead of static strings. perhaps meant use variables instead?

ask_version "app1" "$app1version" ask_version "app2" "$app2version" 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -