[shell][科普]Shell命令用法
来源:互联网 发布:linux给用户root权限 编辑:程序博客网 时间:2024/06/05 23:39
版本:
#Ver 1.0 【2013/08/11 11:59:20】
一、if
1、if判断
if [ ... ]; then fi
Example:
if [ -f "$file" ]; then #如果file是个文件echo "${file}是一个文件。"fi #if 结束
2、if else判断
if [ ... ]; thenelsefi
Example:
if [ -f "$file" ]; then #如果file是个文件echo "${file}是一个文件。"elseecho "${file}不是一个文件。"fi #if 结束
3、if else if 判断
if [ ... ]; thenelif [ ... ]; thenelsefi
Example:
if [ -f "$file" ]; then #如果file是个文件echo "${file}是一个文件。"elif [ -d "$file" ]; then #如果file是个文件夹echo "${file}是一个文件夹。"elseecho "我也不知到${file}是啥!。"fi #if 结束
二、for 循环
for var in ....; do ....done
Example:
for var in A B C; doecho "$var"done
三、while 循环
while [ ... ]; dodone
其中
-lt less than 小于-gt great than 大于-ge great equal 大于等于-le less equal 小于等于-eq equal 等于
Example:
x=0while [ "$x" -lt 10 ]; doecho "$x"x=`expr $x + 1` #注意:` (1的左面那个键)和 ' (Enter的左面那个键)是有区别的done
四、Case
case ... in ...) do something here ;;esac
Example:
echo "你喜欢哪个水果"for var in "香蕉" "桔子" "苹果" "大丫梨"; do case $var in "香蕉") echo "靠,竟然喜欢$var";; "桔子") echo "$var有皮...";; "苹果") echo "$var很好吃";; "大丫梨") echo "好$var";; *) echo "还有这种水果?" esacdone
五、函数
func(){}或者如果你闲的无聊,可以这样写
function func(){}
1、没有参数
Example:hello(){ echo "Hello World."}echo "call function hello..."helloecho "function end..."
2、有参数
Example:
hello(){ echo "Hello World $1"}echo "call function hello..."hello "!!!!!"echo "function end..."
六、一些注意点
由于太多单拎出来。
以下是地址
!这里是地址!
- [shell][科普]Shell命令用法
- shell 命令$用法
- shell命令trap用法
- SHELL test [ 命令用法
- shell命令trap用法
- shell命令用法记录
- SHELL test [ 命令用法
- shell test命令用法
- SHELL test 命令用法
- SHELL test [ 命令用法
- shell find命令用法
- shell命令--date用法
- shell 的cut 命令用法
- shell 的cut 命令用法
- shell脚本部分命令用法
- linux shell cut 命令用法
- shell命令中"-"的用法
- shell date 命令高级用法
- HDU-1032
- 并查集基础知识
- 如花美眷,似水流年。
- codeforces 34D - Road Map DFS
- 使用PushMeBaby测试推送,log显示成功但设备没有收到信息的同学来看!
- [shell][科普]Shell命令用法
- HDU-1076
- iOS: 枚举类型 enum,NS_ENUM,NS_OPTIONS
- poj 1226 Substrings
- Android 设置屏幕亮度
- 【Python的脸】——解析
- HDU-1084
- (Jquery功能篇) JPage分页控件实例代码
- hdu1115 Lifting the Stone (多边形重心)