shell 程序错,
发表于 : 2008-05-30 16:50
最近学习编写shell 脚本,发现了些问题;
问题 1,>
#!/bin/sh
echo "What is your favourite OS?"
select var in "Linux" "Gnu Hurd" "Free BSD" "Other"; do
break
done
echo "You have selected $var"
保存为 11.sh ,并将 11.sh 改为可执行文件
运行:
...................................................................
wyb@wyb-desktop:~/桌面$ chmod +x 11.sh
wyb@wyb-desktop:~/桌面$ ./11.sh
What is your favourite OS?
./11.sh: 3: select: not found
./11.sh: 4: break: not found
./11.sh: 5: Syntax error: "done" unexpected
.........................................................................
请问这是为什么????
还有另一个程序也运行不成功,请问程序那里有错误???
...........................................................................................
#!/bin/sh
#备份目录函数
backup_dir()
{
dir_test
echo "backing ...."
tar xzvf /tmp/back.tar.gz $DIRECTOPY
}
#恢复目录函数
restore_dir()
{
dir_test
echo "正在恢复"
tar xzvf /tmp/backup.tar.gz
}
#验证目录函数
dir_test()
{
#输入要备份的目录名
echo -e "please intput the directory name of backup file :\c"
#度目录名
read DIRECTORY
#判断是否是目录
if [!-d &DIRECTORY]
then
echo "sorry ,&DIRECTORY is not a directory"
exit 1
fi
cd $DIRECTORY
}
clear
#ANS = y
while [&ANS = Y -o &ANS = y]
do
echo "======================================================="
echo "= backup-Restore Menu = "
echo "-------------------------------------------------------"
echo " 1:Backup Directory "
echo " 2:restore Directory "
echo " 0: Exit "
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo -e "please input a choice (0-2): \c"
read CHOICE
case "$CHOICE" in
1) backup_dir ;;
2) restore_dir ;;
0) exit 1 ;;
*) echo "Invalid choice!"
exit 1 ;;
esac
if [$? -ne 0]
then
echo "Program encounter error!"
exit 2
else
echo "Operate sucessfully !"
fi
echo -e "would you like to continue ? y/Y to continue ,any other key to exit :\c"
read ANS
clear
done
...................................................................
运行时,提示:
[: 74: missing ]
./myshell.sh: 74: ANS: not found
./myshell.sh: 74: ANS: not found
请指点一下《《《,谢谢!!!!
问题 1,>
#!/bin/sh
echo "What is your favourite OS?"
select var in "Linux" "Gnu Hurd" "Free BSD" "Other"; do
break
done
echo "You have selected $var"
保存为 11.sh ,并将 11.sh 改为可执行文件
运行:
...................................................................
wyb@wyb-desktop:~/桌面$ chmod +x 11.sh
wyb@wyb-desktop:~/桌面$ ./11.sh
What is your favourite OS?
./11.sh: 3: select: not found
./11.sh: 4: break: not found
./11.sh: 5: Syntax error: "done" unexpected
.........................................................................
请问这是为什么????
还有另一个程序也运行不成功,请问程序那里有错误???
...........................................................................................
#!/bin/sh
#备份目录函数
backup_dir()
{
dir_test
echo "backing ...."
tar xzvf /tmp/back.tar.gz $DIRECTOPY
}
#恢复目录函数
restore_dir()
{
dir_test
echo "正在恢复"
tar xzvf /tmp/backup.tar.gz
}
#验证目录函数
dir_test()
{
#输入要备份的目录名
echo -e "please intput the directory name of backup file :\c"
#度目录名
read DIRECTORY
#判断是否是目录
if [!-d &DIRECTORY]
then
echo "sorry ,&DIRECTORY is not a directory"
exit 1
fi
cd $DIRECTORY
}
clear
#ANS = y
while [&ANS = Y -o &ANS = y]
do
echo "======================================================="
echo "= backup-Restore Menu = "
echo "-------------------------------------------------------"
echo " 1:Backup Directory "
echo " 2:restore Directory "
echo " 0: Exit "
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo -e "please input a choice (0-2): \c"
read CHOICE
case "$CHOICE" in
1) backup_dir ;;
2) restore_dir ;;
0) exit 1 ;;
*) echo "Invalid choice!"
exit 1 ;;
esac
if [$? -ne 0]
then
echo "Program encounter error!"
exit 2
else
echo "Operate sucessfully !"
fi
echo -e "would you like to continue ? y/Y to continue ,any other key to exit :\c"
read ANS
clear
done
...................................................................
运行时,提示:
[: 74: missing ]
./myshell.sh: 74: ANS: not found
./myshell.sh: 74: ANS: not found
请指点一下《《《,谢谢!!!!