首页 > 系统服务 > 详细

linux shell命令之列表

时间:2021-04-12 15:23:11      阅读:39      评论:0      收藏:0      [点我收藏+]

列表由一串命令用与运算&&和或运算||连接而成
与命令的基本格式为:
命令1 && 命令2 && 命令3 && 命令4 && ... && 命令n

或命令的基本格式为:
命令1 || 命令2 || 命令3 || 命令4 || ... || 命令n

vi andlist1.sh
#!/bin/bash

#if条件是一个与列表

if [ -n "$1" ] && echo "The lst argument=$1" && [ -n "$2" ] && echo "The 2nd argument=$2"
then
#只有与列表命令都执行完,才执行下面的命令
echo "At least TWO arguments are passed to this script."
else
echo "Less than TWO argements are passed to this script."
fi
exit 0

./andlist1.sh CAI
The lst argument=CAI
Less than TWO argements are passed to this script.
./andlist1.sh CAI WU
The lst argument=CAI
The 2nd argument=WU
At least TWO arguments are passed to this script.

./andlist2.sh CAI
Usage: andlist2.sh 3 arguments
echo $?
68

./andlist2.sh CAI WU TANG
Correct arguments are passed to this script.
echo $?
0

vi orlist.sh
#!/bin/bash

MAXARGS=3
ERROR=68

#与andlist2.sh脚本相比,仅修改了test语句

test $# -eq $MAXARGS || (echo "Usage: `basename $0` " $MAXARGS arguments && false) || exit $ERROR

echo "Correct arguments are passed to this script."
exit 0
./orlist.sh CAI
Usage: orlist.sh 3 arguments
echo $?
68
./orlist.sh CAI WU TANG
Correct arguments are passed to this script.
echo $?
0

 

linux shell命令之列表

原文:https://www.cnblogs.com/zhudaheng123/p/14647129.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!