巴什
#!/bin/bash
echo "Please enter your name."
read name
then
echo "Good day $name, here is your calendar for this month:"
cal
echo "Today is" `date +%A`
if test $date -lt friday
then
echo "TGIF"
fi
答案1
所需的权限是执行权限。但是你的脚本中有一些错误,尝试运行它,它会清楚地显示第一个错误
$ chmod u+x jason.sh
$ ./jason.sh
Please enter your name.
Jason
./jason.sh: line 4: syntax error near unexpected token `then'
./jason.sh: line 4: `then'
修复它并再次运行,你会得到
$ ./jason.sh
Please enter your name.
Jason
Good day Jason, here is your calendar for this month:
February 2020
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
Today is Friday
./jason.sh: line 7: test: -lt: unary operator expected
您不能像这样比较日期,请检查如何在 shell 中比较两个日期?
答案2
要执行脚本,您需要可执行和读取权限。最后,这是解释性语言,内核需要读取它(逐行)。授予这些权限的命令是:”
chmod u+rx script.sh
当然,您可以仅将读取权限作为 shell 解释器的参数来运行它:
bash script.sh
答案3
如果我们不在前台以 root 身份运行,我们需要执行脚本的权限。
chmod +x scriptName.sh
而且脚本中语法错误很少,您可以使用下面的脚本。
#!/bin/bash
echo "Please enter your name."
read name
echo "Good day $name, here is your calendar for this month:"
cal
echo "Today is" `date +%A`
if [ "`date +%A`" == Friday ]
then
echo "TGIF"
fi
答案4
你好@Jason,你可以试试这个
chmod u=rx,g=x,o=rwx jason.sh