gnome-terminal --tab -e "
sh -c '
 gedit'/media/ubuntuman/Onces And for Al/scripts/faceBook' & ;
 sudo cpulimit -e ubuntu-tweak -l 80;'"

This is the piece of code I want to edit. The special character ' (single quote) in of sh -c will conflict with the single quote of gedit, how can I solve it?

I also find that if I run the first job in the background, the terminal doesn't execute the second job of sudo cpulimit bla bla ... Why?


Please try the following command, it should start both jobs:

gnome-terminal --tab -e "
sh -c '
 (gedit /media/ubuntuman/Onces\ And\ for\ Al/scripts/faceBook &) ;
 sudo cpulimit -e ubuntu-tweak -l 80;'"

Parentheses denote a subshell in bash. To quote the man page:

   (list) list is executed in a subshell environment (see  COMMAND  EXECU‐
          TION  ENVIRONMENT below).  Variable assignments and builtin com‐
          mands that affect the  shell's  environment  do  not  remain  in
          effect  after  the  command completes.  The return status is the
          exit status of list.
  • it doesn't work – Ahmed Zain El Dein Sep 16 '14 at 10:20
  • 1
    @AhmedZainElDein when something fails, please explain how. Just saying "It doesn't work" is not very useful. – terdon Sep 16 '14 at 14:53
  • sorry for that :) it works as a syntax but as logic it opens in gedit facebook once and plain new documents he doesn't consider it absolute path – Ahmed Zain El Dein Sep 16 '14 at 14:56
  • @AhmedZainElDein: I must admit that I didn't really understand the purpose of such launcher but actually I'm able to have the gnome terminal, gedit and a third job started this way without the issue of gedit closing the last process. Indeed some detailed feedback would help – Sylvain Pineau Sep 16 '14 at 14:59
  • gnome-terminal --tab -e " sh -c ' (gedit '/media/ubuntuman/Onces\ And\ for\ Al/scripts/faceBook' &) ; sudo cpulimit -e ubuntu-tweak -l 80;'" (gedit '/media/ubuntuman/Onces\ And\ for\ Al/scripts/faceBook' &) must open the file named in the absolute path , Right ? this doesn't happen what happen is Gedit open separated new documents named Onces,And,for,faceBook, scripts – Ahmed Zain El Dein Sep 16 '14 at 15:15

Since you're not using any special (i.e., special for the shell) characters in the filename, and since you're not giving any further commands, you can use the -x option and leave out the surrounding quotes for the shell:

gnome-terminal --tab -x bash -c \
   'gedit "/media/ubuntuman/Onces And for Al/scripts/faceBook" & \
    sudo cpulimit -e ubuntu-tweak -l 80'

Note that an & need not be followed by a ;.

  • thanks for suggestion ,but can u please suggest me something for the same commands --tab -e sh-c – Ahmed Zain El Dein Sep 16 '14 at 10:24
  • @AhmedZainElDein 1. You don't need to use sh. bash will work fine. If you insist on using sh, then just replace bash with sh in my command. 2. The -x option replaces -e. – muru Sep 16 '14 at 10:25
  • the point is after this command gnome-terminal --tab -x bash -c \ 'gedit "/media/ubuntuman/Onces And for Al/scripts/faceBook" & \ sudo cpulimit -e ubuntu-tweak -l 80' i add more sets of lines like other --tap -e so the surrounding quotes can be left for the shell in that case too ? – Ahmed Zain El Dein Sep 16 '14 at 10:37
  • @AhmedZainElDein and why are you doing this? I can see the point behind running sudo cpulimit ..., but why do you have to run gedit from inside the terminal? Where are you going to use this? – muru Sep 16 '14 at 10:49
  • it is a script to run some tasks once it is executed :) can we fix this ? – Ahmed Zain El Dein Sep 16 '14 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.