现在,我已经知道这意味着有一个错误,但我找不到它。您能帮忙检查我的代码并尝试找出问题所在吗?错误消息围绕我创建的日期函数。所有其他功能在此代码中都可以正常工作。
错误:
sguthrie1@cs:~$ ./finalproject.sh -d
Segmentation fault (core dumped)
代码:
function check
{
echo "usage: hw14.sh option argument
Please enter one or more options or arguments."
exit
}
function date
{
if [[ $myvar == "-d" ]]
then date "+%d %B,%Y"
fi
}
function host
{
if [[ $myvar == "-h" ]]
then hostname
fi
}
function who
{
if [[ $myvar == "-w" ]]
then whoami
fi
}
function help
{
if [[ $myvar == "-help" ]]
then echo "
valid options:
-d = display today's date in day-month-year format
-h = display name of computer you are currently working on
-w = display who you are logged in as
arguments:
Any argument entered is checked to see if it is a file name
"
fi
}
if [ $# -le 0 ]
then check
fi
for myvar
do
if [[ $myvar == "-"* ]]
then date; host; who; help
fi
done