Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I run three commands in a launcher? The commands are:

cd /home/seraex/MyDoc
rm MyDoc.tgz
tar cfz MyDoc.tgz *

which go to my documents folder, delete the old backup and then make a new backup.

I have made a sh script with those commands and I made the launcher run the script. This works, but I want to make the launcher run the commands directly. I'm using Ubuntu 10.10

The Ubuntu site says

Unfortunately launchers do not have access to the Bash environment so you cannot just include the multi commands

share|improve this question
When you say "launcher" what desktop are you using? Would also help to list the version of Linux. In general, multiple commands can be chained together. See – Julian Knight Jun 25 '12 at 12:43
I would put those lines in a file start it with #!/bin/bash and chmod +x it and then have the launcher use that file as the command name. – Dan D. Jun 25 '12 at 15:03
@ julian , the post say that i can use -> but when I use it it say 'There was an error creating the child process for this terminal' – seraex Jun 25 '12 at 15:05
@seraex: No, the post doesn't say that you can use ->. The example uses ;. – Ben Voigt Jun 25 '12 at 15:07
@ julian same error 'There was an error creating the child process for this terminal' for ; and when i google i get that 'Some programs need additional commands before they can be started. Java programs need to be started from within the directory in which their files exist. Others must be run within Wine. Unfortunately launchers do not have access to the Bash environment so you cannot just include the needed commands.' thanks for ur help. – seraex Jun 25 '12 at 15:19

You can always pass your commands as arguments for bash.

Some working examples:

bash -c "rm -fR /some/dir/to_delete; mkdir /hello; touch /hello/"

This should work to delete /some/dir to delete then create dir /hello and write baz to file /hello/

bash -c 'rm -fR "/some/dir to delete"; mkdir "/hello"; echo "baz" > "/hello/"'

These will not work correctly:

Be careful with quotes, this will break things as because quoting error command will be rm -fR "/some/dir/to and everything after that is ignored (or to be more precise delete"; mkdir /hello" is expanded if $0 is used within command):

bash -c "rm -fR "/some/dir/to delete"; mkdir /hello"
        ^-------^            ^
       quoted part          unquoted whitespace here

And here is another thing to mention. If you want ~ to expand as home directory and your file path may contain whitespaces need quoting this will not work. File ~/hello world.tmp is not created in right place but instead it tries to find directory named ~ from current working directory whatever it is and create file here however ~/ is created under home dir:

bash -c 'echo "Hello World" > "~/hello world.tmp"; cd /; ls * > ~/;'
                              fully quoted filename prevents ~ from expanding

Instead you must use quoting like this to allow ~ expanding:

bash -c 'echo "Hello World" > ~/"hello world.tmp"; cd /; ls * > ~/;'
                             now ~ is not quoted at all

Here is line for your case:

Strong quoting ' is needed for special char *, if not escaped it will expand too early.

bash -c 'cd "/home/seraex/MyDoc"; rm -f MyDoc.tgz; tar -czf MyDoc.tgz *'

OR if you want to use more general ~ as home dir then use this:

bash -c 'cd ~/"MyDoc"; rm -f MyDoc.tgz; tar -czf MyDoc.tgz *'

So, this is just one possible way to do what you need, it may or may not work directly too (without bash -c and outer quotes). At least with KDE 4 launcher it will handle command cd ~/"MyDoc"; rm -f MyDoc.tgz; tar -czf MyDoc.tgz * without any problems. However other examples should work with any launcher that allows specifying arguments for program and behavior still depends on many things and at least you may want to check that any special characters are expanded at right time.

I have not tested this and cant do that now because answering with my phone but it should work ok. Now tested and I can confirm that it works well

share|improve this answer

You must log in to answer this question.

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