1

I'm trying a new conky theme on my Lubuntu system, and for running it I need to start a bash script:

#!/bin/bash
#sleep 18&&
conky -c /home/mathijs/conky/conky1&&
sleep 1&&
conky -c /home/mathijs/conky/conky2&&
sleep 1&&
conky -c /home/mathijs/conky/conky3&&
sleep 1&&
conky -c /home/mathijs/conky/conkyxx&&
sleep 1&&

When I run the script, the terminal gives me this error:

./start.sh: line 11: syntaxerror: unexpected end of file

Yet in the script there are only 10 lines. I rewrote it by hand, and checked again, but got the same error. What am I missing?

2
  • 1
    And what is the point of adding && after sleep 1. This command is always successful.
    – Pilot6
    Jul 29, 2015 at 14:00
  • One of my first bash scripts, downloaded it as-is!
    – MetNL
    Jul 29, 2015 at 14:09

2 Answers 2

8

The shell metacharacter && expects a command afterwards, that would be run if the first command succeeds.

Thats why you are getting the error message.

For example you have sleep 1&& at the 10th line, now the shell will run sleep 1 and then if it succeeds (exit code 0) then (&&) will run the next command, which is not provided by you. So you would get a unexpected end of file error message.

Also i think you meant to use & instead of &&.

& will take a foreground process to the background so you can do some other stuffs on the foreground. Also that might no be a good idea with sleep command (depends on use case though) as sleep intends to pause the execution of command in the script or the terminal for the amount of time mentioned, if you take it to the background by adding & e.g. sleep 1& the next command will be run instantly as the order of execution will not be synchronized in this case.

2
  • Makes sense haha :3
    – MetNL
    Jul 29, 2015 at 14:05
  • @MetNL Added some points ..please do review those..
    – heemayl
    Jul 29, 2015 at 14:21
1

The last command sleep 1&& expects to have something else.

If you remove last &&, there will be no error.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .