【发布时间】:2014-05-05 16:41:00
【问题描述】:
我目前正在为 Unix 课程做家庭作业,我已经完成了其他所有工作,但我就是不知道我做错了什么。我已经在 csh 中完成了完全相同的脚本(但我们也需要在 bash 中完成。)我已经修复了一些错误,但现在当我尝试运行它时,我得到的是“变量语法” .
我曾尝试使用双括号 for while 和 ifs 在尝试读取输入之前,我也尝试过声明输入的变量 我也试过窃听我班上的几个人,但他们中的大多数人都很笨,只是抄袭其他人。
#/!bin/bash
#
#Menunix - Bash
#
#Usage: menunixb
input = "$(1)"
while [ $input != 5 ]
do
echo Please choose an option
echo 1: List Files
echo 2: Display today's date and time
echo 3: Check whether a file is a directory or not
echo 4: Create a file backup
echo 5: Quit
read input
case $input in
1)
ls
;;
2)
echo -n Time:
date +"%T"
echo Date:
date +"%D"
;;
3)
echo What file do you wish to check
read finput
if [ -d $finput ] ; then
echo $finput is a Directory
elif [ -f $finput ] ; then
echo $finput is a File
else
echo $finput does not exist
;;
4)
echo Please enter filename to backup
read binput
cp $binput{,.bak}
;;
5)
exit 1
*)
echo Please choose a valid input
exit 1
esac
done
#EOF
【问题讨论】:
-
查看代码的语法高亮。提示:引号
-
考虑使用缩进。这使代码更具可读性,因此更易于调试。
标签: bash