For loop in bash
Posted David Cao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了For loop in bash相关的知识,希望对你有一定的参考价值。
10 Bash for Loop In One Line Examples
Bash For Loop Examples In Linux
What Is Bash in Linux?
Bash for Loop In one Line with items
# for i in 1 2 3 4 5 ; do echo "$i" ; done
# for i in {1..5} ; do echo "$i" ; done
# for i in {1..5..1};do echo "$i" ; done
# for planet in Mercury Venus Earth Mars Jupiter Saturn Uranus; do echo $planet; done
Bash for loop C style In One Line with items
# for ((i=1;i<=5;i++));do echo $i;done
Bash For Loop In one line with Command Output
# for i in `seq 1 5`;do echo $i ;done
# for i in `cat test`;do dig $i +short ;done
# for i in `awk \'{print $1}\' test` ;do ping -c 2 $i ;done
Bash For Loop In one Line with variables
# for i in $(cat test);do dig $i +short ;done
# a="a b c"
# for i in $a;do echo $i;done
a
b
c
# a=(a b c)
# for i in ${a[@]};do echo $i;done
a
b
c
# for i in $(seq 1 5);do echo $i ;done
Bash For Infinite Loop In one Line
# for (( ; ; )); do echo "Hello World!"; done
# while true; do echo "Hello World!"; done
# while :; do echo "Hello World!"; done
Bash For Loop In One Line with Files
# for i in *; do echo "Found the following file: $i"; done
# for i in `cat filelist.txt`; do echo ${i}; done;
if a line may include spaces better use a while loop:
# cat filelist.txt | while read LINE; do echo "${LINE}"; done
10 Bash for Loop In One Line Examples
Bash For Loop Examples In Linux
What Is Bash in Linux?
以上是关于For loop in bash的主要内容,如果未能解决你的问题,请参考以下文章