2013年2月23日 星期六

bash script 常用變數技巧



   Bash basic concepts

   http://wiki.bash-hackers.org/scripting/basics

  Bash script parameter substitution

   http://tldp.org/LDP/abs/html/parameter-substitution.html



 ${!varprefix*}${!varprefix@}

Matches names of all previously declared variables beginning with varprefix.

# This is a variation on indirect reference, but with a * or @.
# Bash, version 2.04, adds this feature.

xyz23=whatever
xyz24=

a=${!xyz*}         #  Expands to *names* of declared variables
# ^ ^   ^           + beginning with "xyz".
echo "a = $a"      #  a = xyz23 xyz24
a=${!xyz@}         #  Same as above.
echo "a = $a"      #  a = xyz23 xyz24

echo "---"

abc23=something_else
b=${!abc*}
echo "b = $b"      #  b = abc23
c=${!b}            #  Now, the more familiar type of indirect reference.
echo $c            #  something_else








from 鳥哥


沒有留言:

張貼留言