Shell-Scripting: Syntax error: word unexpected (expecting "in")

时间:2016-10-15 17:05:59

标签: sh

I've searched some sites and also checked the syntax of the case command, but it didn't help. Where is my error?

#!/bin/sh
USER="user"
DIR="/linktodirectory"
###### script ######
case $1 in

As you can see above, i have a "in" there.

start)
su $USER -c "${DIR}/file start"
;;
stop)
su $USER -c "${DIR}/file stop"
;;
restart)
su $USER -c "${DIR}/file restart"
;;
status)
su $USER -c "${DIR}/file status"
;;
*)
echo "Usage: {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0

I'm using Ubuntu 16.04 64-bit.

2 个答案:

答案 0 :(得分:0)

Your first argument $1 should be enclosed in double quotes. Only then is this an argument to the case statement.

case "$1" in

答案 1 :(得分:0)

I am suspecting a file encoding issue at first .

At first your syntax looks okay.. at least the line giving the error.

You could change the case line with double quotes as it has been said already.

If the problem persist , be sure to check file encoding.