简体   繁体   中英

“syntax error near unexpected token `)' ”?

echo "Which number port would you like to power up or down? 1, 2 or 3?"
read string
case "$string" in
    [1]* | [2]* | [3]*) echo "User entered: '$string'" ;;
    *) echo "I don't understand '$string'" ;;
esac

Can anyone shed some light as to why this won't work? New to Bash.

Are you sure you don't have a 'non breakable space' ( https://en.wikipedia.org/wiki/Non-breaking_space )? For instance between *) and echo

I would write it as:

#!/bin/bash

echo "Which number port would you like to power up or down? 1, 2 or 3?"
read string
case "${string}" in
    [123]) echo "User entered: '${string}'" ;;
    *)     echo "I don't understand '${string}'" ;;
esac

Because in your script 11 or 22 and so on is also valid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM