How do I list variables that being with a specific prefix in a bash shell script?
-
Usage is ${!prefix[*] and ${!prefix[@]}
Three arrays
declare -A MyBucketList MyKtbList MyList MyBucketList=([1]="See The Grand Canyon" [2]="Go to Mars" [3]="Climb Mount Everest") MyKtbList=([1]="See The Grand Canyon" [2]="Go to Mars" [3]="Climb Mount Everest") MyList=([1]="See The Grand Canyon" [2]="Go to Mars" [3]="Climb Mount Everest")echo ${!My*} echo ${!My*}
Line 5 just echo any prefix variable beginning with
My
, the result is as follows:$ ./associative_array.sh MyBucketList MyKtbList MyList
© Lightnetics 2024