Unix Shell While循环

首先解释下 unix shell 是什么?
unix shell就是unix系统的命令解释器,比如你敲个ls,它给你返回当前目录下的文件、目录列表,返回这个列表就是shell的工作。

unix shell有哪些种类?
感觉这话有点问题,应该是解释器有哪些种类?但是也可以说unix shell有哪些种类,因为解释器不一样,语法还是稍微有些差别。比较常见的解释器有:csh,ksh,bash。很多系统默认的就是bash,/usr/bin/sh 就是它。

我使用的是什么shell?
你只需要more一下 /etc/passwd,找到你的用户的哪一行,看一下就明白了。

shell怎么切换?
这个很简单,假设你现在想用ksh了,仅仅执行一下: /usr/bin/ksh 或者 /bin/ksh ,你的命令解释器就变成ksh了。那么在shell编程的时候怎么指定呢?你只需要在第一行加入#!/usr/bin/ksh 或者 #!/bin/ksh 就可以了,其它的雷同.
这里顺便说一下 /usr/bin 和 /bin的区别,/bin 会放置一些普通用户不让使用的命令,所以它的目录权限可能会更严一些, 如果没有权限使用这目录就可以用 /usr/bin 了。

现在言归正传:
bash的while loop:
Php代码
语法:  
while [ condition ]   
do
    command1  
    command1  
    commandN  
done  
示例:  
#!/bin/bash  
c=1  
while [ $c -le 5 ]  
do
    echo “Welcone $c times”
    (( c++ ))  
done

语法:
while [ condition ]
do
command1
command1
commandN
done
示例:
#!/bin/bash
c=1
while [ $c -le 5 ]
do
echo “Welcone $c times”
(( c++ ))
done
ksh的while loop:
Php代码
语法:  
while [[ condition ]] ; do
    command1  
    command1  
    commandN  
done  

示例:  
#!/bin/ksh  
c=1  
while [[ $c -le 5 ]]; do
    echo “Welcome $c times”
    (( c++ ))  
done

语法:
while [[ condition ]] ; do
command1
command1
commandN
done

示例:
#!/bin/ksh
c=1
while [[ $c -le 5 ]]; do
echo “Welcome $c times”
(( c++ ))
done
csh的while loop:
Php代码
while ( condition )  
         commands  
     end

#!/bin/csh  
set yname=”foo”
while ( $yname != “” )  
    echo -n “Enter your name : “
    set yname = $<  
    if ( $yname != “” ) then  
        echo “Hi, $yname”
    endif
end
参与0

0同行回答

“答”则兼济天下,请您为题主分忧!

提问者

相关问题

相关资料

相关文章

问题状态

  • 发布时间:2010-10-28
  • 关注会员:0 人
  • 问题浏览:8379
  • X社区推广