【发布时间】:2018-08-05 12:10:17
【问题描述】:
我是 Linux bash 脚本的新手,我似乎找不到我做错了什么。这是我的代码。输入数字 2 和 3,在提示我询问用户我的代码停止后,它不会继续执行 IF ELSE 语句。感谢那些愿意提供帮助的人!
#!/bin/bash
while true
do
clear
echo "Please enter one of the following options"
echo "1. Move empty files"
echo "2. Check file size"
echo "3. Which file is newer"
echo "4. File check rwx"
echo "5. Exit".
echo -e "Enter Choice:"
read answer
case "$answer" in
1) ./move_empty
exit 55 ;;
2) echo "Enter a filename"
read filename
if [ -f $filename ];
then ./file_size
fi
;;
3) echo "Enter first file:"
read filename
echo "Enter second file:"
read filename2
if [ ! -f "$filename" ];
then
echo "Supplied file name" $filename "does not exist";
if [ $filename" -nt $filename" ]; then
echo $filename "is newer"
exit 1fi
fi ;;
5) exit ;;
esac
done
【问题讨论】:
-
如果每行缩进4个空格,它应该像源代码一样格式并且可读。
-
将第一行从
!/bin/bash改为#!/bin/bash。 -
它已经改变了,感谢 fang!
-
你好,我查过了。提示用户输入后,我的脚本仍然无法工作。我的 if-else 语句不起作用
标签: linux bash shell if-statement scripting