总结:
shell脚本对空格有严格的规定,赋值语句等号两边不能有空格,而字符串比较,等号两边必须有空格 if语句,中括号前后一定要加空格否则会报错 shell脚本变量…
变量名外面的花括号是可选的,加不加都行,加花括号是为了帮助解释器识别变量的边界,建议给所有变量加上花括号,这是个好习惯,既便于阅读,又不易出错
1.[root@localhost ~]# ./ceshi.sh
Enter a file name:
ceshi.sh
The file ceshi.sh exists!
text.sh
执行报错
[root@localhost ceshi]# bash text1.sh
enter your login name:root
text1.sh: line 13: [root=root]: command not found
text1.sh: line 17: echoyou are not root,so who are you dmxy: command not found
解决方案:空格
3.
报错
解决方案:查空格
错误二
Echo后面的没有留位置,导致shell脚本识别不出来命令的输入输出
4.查找文件中的关键字
报错已解决;
text4.sh: line 16: echo"grub"does not occurs in grub.cfg: command not found
字符写错 grub 应该是grub
5.根据当前系统时间输出结果
6.根据不同的菜单选择输出不同的信息