0

I have just started to learn shell scripting on Ubuntu and thought of writing a basic script which starts conky and plank and placing it in /usr/bin so that I can run it as a command.I did make it an executable too.

#!/bin/bash
echo `conky -q &`
echo `plank  &`

Only conky gets started up.

Cyatos
  • 21
  • 6
  • what's this `fi` at the end? Note also that the command will be executed but then will finish as soon as the script finishes, so your programs won't execute. You may want to `source` it. More info in [What is the difference between executing a bash script and sourcing a bash script?](http://superuser.com/q/176783/204979) – fedorqui Jun 11 '15 at 13:45
  • Sorry fi was a mistake.I tried sourcing it too and it didn't work.Is there something I'm doing wrong? – Cyatos Jun 11 '15 at 14:20

1 Answers1

0

You don't need the echoes or the back quotes. Just:

#!/bin/bash
conky -q &
plank &

This should also work:

#!/bin/bash
echo `conky -q` &
echo `plank` &

So you put in background the whole command.

  • That works perfectly.Thanks.Can you provide a link explaining said solution.It would really help me out.Thanks in advance – Cyatos Jun 11 '15 at 14:38
  • The back-quotes capture that output from running the program (`conky` or `plank`) in background in a script. The chances are, that's empty; it might include some information. You then passed that information to `echo` for it to write to standard output, which would have happened even if you didn't capture the standard output. As to why only `conky` ran: it seems that `bash` ignores the backgrounding and waits for the command to complete. I'm not convinced that's correct behaviour — it is counter-intuitive to me, at least. If I run something in the background, I don't want the shell waiting. – Jonathan Leffler Jun 11 '15 at 14:41
  • Because even if you put the & between the back quotes, there's no & for the echo command, so it stops there. With your solution you should put the & after the back quotes. – Ricardo Devis Agullo Jun 11 '15 at 14:49
  • Thanks.That makes sense. – Cyatos Jun 11 '15 at 14:56