linux的for循環的寫法
Linux下使用while…;do done語句來寫循環語句,其實也非常簡單,比如說,我們要寫一個循環5次的命令。
可以這樣來寫:I=1While [$I<=5];do語句…DoneI=$(($I+1))其中,I=$(($I+1))說明我們這個循環每次遞增的數為1,也就是在I的基礎上加1,這樣就形成了循環了。====================================腳本1:#!/bin/shfor loop in 1 2 3 4 5doecho $loopdone腳本2:#!/bin/shfor loop in "orange red blue grey"doecho $loopdone有了""就是字符串,只循環一次第二個循環的循環變量會依次為orange red blue grey中的每一個。
linux中使用for語句創建命令行上所有整數只和的shell
[root@localhost ~]# cat e1#!/bin/basha=$*sum=0for i in $ado sum=`expr $sum + $i`doneecho $sum[root@localhost ~]# sh -x e1 123 45 67+ a='123 45 67'+ sum=0+ for i in '$a'++ expr 0 + 123+ sum=123+ for i in '$a'++ expr 123 + 45+ sum=168+ for i in '$a'++ expr 168 + 67+ sum=235+ echo 235235。
linux中使用for語句創建命令行上所有整數只和的shell
[root@localhost ~]# cat e1
#!/bin/bash
a=$*
sum=0
for i in $a
do
sum=`expr $sum + $i`
done
echo $sum
[root@localhost ~]# sh -x e1 123 45 67
+ a='123 45 67'
+ sum=0
+ for i in '$a'
++ expr 0 + 123
+ sum=123
+ for i in '$a'
++ expr 123 + 45
+ sum=168
+ for i in '$a'
++ expr 168 + 67
+ sum=235
+ echo 235
235
linux 簡單語句
wait [n 。]
Wait for each specified process and return its termination status. Each n may be a process ID or a job specification; if a job spec is given, all processes in that job's pipeline are waited for. If n is not given, all currently active child processes are waited for, and the return status is zero. If n specifies a non-existent process or job, the return status is 127. Otherwise, the return status is the exit status of the last process or job waited for.
等待每個參數中的進程,并返回進程退出值。 n可以是進程id或者job specification(不會翻譯了),
如果給了job specification, wait指令會等待其中所有的進程。
如果沒有給n,就會等待所有的子進程,并返回0.
如果n是一個不存在的進程id或者job speicification,就返回127
否則,返回值是等待的最會一個進程或者Job的退出值。
轉載請注明出處華閱文章網 » linuxfor語句