3.5.2 Tilde Expansion
echo "~" # only begin with an unquoted character is considered a tilde-prefix
echo ~
touch t.txt
ls ~+/t.txt # use the shell variable PWD replaces the tilde-prefix
mkdir td
cd td
ls ~-/t.txt # use the OLDPWD variable replaces the tilde-prefix
3.5.3 Shell Parameter Expansion
3.7 Arrays
$ declare -a array # declare a indexed array
declare -a arr[2] # 2 is ignored
$ echo ${array[@]} # all members of the array name
array=([0]=2 [1]=3) # the form [subscript]=string .
$ echo ${array[*]} #
array=(2 3 4 5 6) # index array do not require anything but string
IFS="," # set IFS
echo "${array[*]}" # expands to a single word with the value of each array member separated by the first character of the IFS varaible
echo "${array[@]}" # expands each element of name to a separated word.
echo ${#{array[@]} #expands to the length of ${name[subscript]}
echo ${array[-2]} # intepreted ass relative to one greater than the maximum index of name
echo ${array} # Referencing an array varaible without a subscript is equivalent with a subscript of 0
echo ${noexist[2]} # Any reference to a variable using a valid subscript is legal, and bash will create an array if necessary.
echo ${!array[@]} # obtain the keys of an array
echo ${!array[*]} # the same to @
unset array[0] # destroy the array element
unset array # destroy arrays
$ declare -A Array # declare a associative array
Array[a]=123 #using the [subscript]=value to assign a value
Array+=([c]=7 [d]=8) # use the operator+
declare -aA arrOrArr # -A takes precedence
read -a stdarr # assign a list of words read from the standard input to an array.
filename expands
标签:name,array,echo,exercise,subscript,expands,declare,bash
From: https://www.cnblogs.com/ysjblog/p/17131221.html