如何在linux shell中if表达语句

linux shell\u7684if\u8bed\u53e5

echo "\u4f60\u7ee7\u7eed\u5417\uff1fY or N"
read ANSWER
if [ \u201c$ANSWER\u201d = \u201cY\u201d -o \u201c$ANSWER\u201d = \u201cy\u201d ] ; then
echo "\u4f60\u9009\u62e9\u4e86$ANSWER";
elif [ \u201c$ANSWER\u201d = \u201cN\u201d -o \u201c$ANSWER\u201d = \u201cn\u201d ] ; then
echo "\u4f60\u9009\u62e9\u4e86$ANSWER";
else
echo "\u8f93\u5165\u9519\u8bef"
exit
fi
-----\u4f60\u8bd5\u8bd5

\u5e94\u8be5\u8fd9\u4e48\u5339\u914d\uff1a
$a =~ ^[[:alpha:]]+$

如果仅仅是在ABC 后运行 ls abc.txt
那你让它们先后运行就是了,不需要if:
ABC;  ls abc.txt
或者:
ABC
ls abc.txt

if 只有在下列情况下是必要的:
1. ABC 成功,返回0时运行 ls abc.txt
ABC && ls abc.txt
2. ABC 失败,返回非0时运行 ls abc.txt
ABC || ls abc.txt

当然,也有 可能我的理解 有问题,那就抱歉了!

你说的是if 的用法吗
if [ your expression]; then
ls abc.txt
else
echo "your script!"
fi

#/bin/bash
read AAA
if [ $AAA = 'ABC' ]; then
ls abc.txt
else
echo 'Please input ABC!'
fi

扩展阅读:linux如何打开shell终端 ... linux shell编程怎么运行 ... linux shell怎么打开 ... linux shell脚本编写教程 ... linux shell 命令 ... linux启动显示shell ... linux shell read ... linux中怎么进入shell ... linux如何进入shell ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网