bash shell for复合语句

6月 9, 2020 |

for x in $(ls ); do echo "$x"; done; //Command Substitution
for ((x=0; x<5; x++)); do echo "$x"; done; //Arithmetic expression
for x in {01..10..2} ; do echo "$x"; done //Brace Expansion
从1增长到10,步长为2
for x in ${PATH//:/ }; do echo "[$x]"; done //Shell Parameter Expansion
使用''替换PATH中的':'符号,
arr=(1 2 3 4); for x in ${arr[@]};do echo "$x"; done //Shell Parameter Expansion
for, do done是三个语句组成的复合语句,如果三个语句在同一行的时候';'不可少
所以for x in parameter1 parameter2 ... parameterN ;最后转换成这种空格分隔的序列,才能被shell解析器正确执行

Posted in: Linux

Comments are closed.