[beyes@localhost ~]$ echo $PS4
+
#!/bin/bash
checkname()
{
if [ "$USER" = "beyes" ];then
return 0
else
return 1
fi
}
checkuid()
{
if ["$UID" -eq 500 ]; then
return 0
else
return 1
fi
}
checkname
if [ "$?" -eq 0 ]; then
echo "check name ok!"
else
echo "check name failed"
fi
checkuid
if [ "$?" -eq 0 ]; then
echo "check uid ok!"
exit 0
else
echo "check uid failed"
exit 1
fi
[beyes@localhost ~]$ sh sp4.sh
sp4.sh: line 7: syntax error near unexpected token `else'
sp4.sh: line 7: ` else'
[beyes@localhost ~]$ sh sp4.sh
check name ok!
sp4.sh: line 14: [500: command not found
check uid failed
[beyes@localhost ~]$ export PS4='+$LINENO: {${FUNCNAME[0]}} '
[beyes@localhost ~]$ sh sp4.sh
check name ok!
sp4.sh: line 14: [500: command not found
check uid failed
[beyes@localhost ~]$ sh -x sp4.sh
+21: {} checkname
+5: {checkname} '[' beyes = beyes ']'
+6: {checkname} return 0
+22: {} '[' 0 -eq 0 ']'
+23: {} echo 'check name ok!'
check name ok!
+28: {} checkuid
+14: {checkuid} '[500' -eq 500 ']'
sp4.sh: line 14: [500: command not found
+17: {checkuid} return 1
+29: {} '[' 1 -eq 0 ']'
+33: {} echo 'check uid failed'
check uid failed
+34: {} exit 1
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |