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
Post a Comment