Skip to content

Instantly share code, notes, and snippets.

@tcpdump-examples
Created January 23, 2022 14:23
Show Gist options
  • Select an option

  • Save tcpdump-examples/3c070de27d433185903b35fc79d50693 to your computer and use it in GitHub Desktop.

Select an option

Save tcpdump-examples/3c070de27d433185903b35fc79d50693 to your computer and use it in GitHub Desktop.

1、罗列式

[code] for VARIABLE in 1 2 3 4 5 .. N do command1 command2 commandN done [/code]

[code] #!/bin/bash for i in 1 2 3 4 5 do echo "Welcome $i times" done [/code]

2、使用rang

[code] #!/bin/bash for i in {1..5} do echo "Welcome $i times" done [/code]

3、使用rang and step

[code] echo "Bash version ${BASH_VERSION}..." for i in {0..10..2} do echo "Welcome $i times" done [/code]

4、使用seq

[code] for i in seq 1 5 do echo "Welcome $i times" done [/code]

5、和高级语言一样的for

[code] for (( EXP1; EXP2; EXP3 )) do command1 command2 command3 done [/code]

[code] #!/bin/bash for (( c=1; c<=5; c++ )) do echo "Welcome $c times..." done [/code]

[code] #!/bin/bash for (( ; ; )) do echo "infinite loops [ hit CTRL+C to stop]" done [/code]

参考: what is bash in linux

bash for loop in one line

bash for loop examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment