BASH: Concatenated string variable unable to be used by select inside function -


in "hostmenu" function below want concatenated strings $site , $system used identify array used build next menu. functions "sitemenu" , "sysmenu" set 2 required variables needed set $sitesystem. arrays defined outside of functions. problem having "$sitesystem" ends empty when select goes use it. echo of "$sitesystem shows positional parameters "site""system" (example: "siteasysb") instead of strings defined in array "$siteasysb". how can have have select use "$sitesystem" variable?

#!/bin/bash main () {     sitemenu     sysmenu     hostmenu } ## functions omitted set $site , $system ## hostmenu () {     ps3="please choose $site $system device connect to.."     clear     sitesystem=("$site""$system")     echo $sitesystem     select opt in "${sitesystem[@]}"         case $opt in ## omitted selected host section ## ;; "return previous system menu") sysmenu ;; "return site menu") sitemenu ;; "quit") break ;; *) echo invalid option;; esac done } siteoptions=("sitea" "siteb" "quit") sysoptions=("sysa" "sysb" "return site menu" "quit") siteasysa=("a" "b" "return previous system menu" "return site menu" "quit") siteasysb=("a" "b" "return previous system menu" "return site menu" "quit")  `main "$@" 

to use value of variable name of variable, put ! @ beginning of variable name indirect. do:

since want whole array [@], need include in $sitesystem

sitesystem="$site$system[@]" select opt in "${!sitesystem}" 

see how iterate on array using indirect reference?


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -