Usage of $ {} in shell 1. truncation function $ {file # */}: remove the first/and its left string: dir1/dir2/dir3/my.file.txt $ {file ##*/}: remove the last/and its left string: my.file.txt $ {file #*.}: remove the first one. and the string on the left: file.txt $ {file ##*.}: remove the last one. and the left string: txt $ {file %/*}: remove the last string/and the right string:/dir1/dir2/dir3 $ {file % /*}: remove the first/and its right string: (null) $ {file %. *}: remove the last one. and its right string:/dir1/dir2/dir3/my. file $ {file %. *}: remove the first one. and its right string:/dir1/dir2/dir3/my memory method: [list] # is to remove the left, # The last % is to remove the right, % first 2. string Extraction A single symbol is the minimum matching condition. The two symbols are the maximum matching. $ {File: 0: 5}: extract the leftmost 5 bytes:/dir1 $ {file: 5: 5}: extract 5 consecutive bytes to the right of 5th Bytes: /dir23. string replacement $ {file/dir/path}: Replace the first dir with path:/path1/dir2/dir3/my.file.txt $ {file/dir/path }: replace all dir with path:/path1/path2/path3/my.file.txt 4. assign values to different variable states (not set, null, non-null): $ {file-my.file.txt}: Use my.file.txt as the return value if the specified filepath is not set. (Null and non-null values are not processed) $ {file: -my.file.txt}: if the specified filepath is not set to a null value, use my.file.txt as the return value. (When non-empty value is used, ignore empty values file=my.file.txt}: If empty values are set to empty values or non-empty values, use my.file.txt as the return value. (Not set) $ {file: my.file.txt}: Use my.file.txt as the return value if the specified fileis a non-empty value. (When no value is set and no value is set, ignore variable file=my.file.txt}: If variable file.txt is not set, use my.file.txt as the return value, and assign $ file to my.file.txt. (Null and non-null values are not processed) $ {file: Empty my.file.txt}: if the specified filepath is not set to a null value, use my.file.txt to return the value, and assign $ file to my.file.txt. (Do not process non-null values) $ {file? My.file.txt}: if the specified filepath is not set, output my.file.txt to STDERR. (Null and non-null values are not processed) $ {file :? My.file.txt}: if the specified filepath is not set to an empty value, output my.file.txt to STDERR. (Do not handle non-null values.) Note: ": +" does not include null values. ":-", ": =" and so on, as long as there is a number, it contains a null value (null ). 5. variable Length $ {# file} 6. array Operation A = (a B c def) $ {A [@]} or $ {A [*]} can get a B c def (number of all groups) $ {A [0]} returns a (number of the first group), and $ {A [1]} returns the number of the second group... you can get 4 for $ {# A [@]} or $ {# A [*]} (number of all groups) $ {# A [0]} can get 1 (that is, the length of the first number of groups (), $ {# A [3]} can get 3 (length of the fourth number (def)