Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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


In a script I want to run a command in a separate window so that output of the command will show in a new window (which is an output stream like top) and they do not interfere each other. For this I use gnome-terminal -x bash -c 'command'.
For example: "\ can be printed using gnome-terminal -x bash -c 'echo "\"\\"; read ' or gnome-terminal -x bash -c 'echo -e "\x22\x5c"; read '. I just don't interested in hexadecimal as it will not work with other command than echo.


How can I print "'?
Executing gnome-terminal -x bash -c 'echo "\"\'"; read '
Is there any alternative to gnome-terminal -x bash -c to run a command in a new window ? (Not in background).

My case

gnome-terminal -x bash -c 'perl -le 'open(P,"sudo nethogs lo |");  $|=1;
while(<P>){ print "------","$_"; }'  >> /tmp/a.txt'`  

What I do currently is

  1. Assign perl code to a variable cmd_perl='open(P,"sudo nethogs ppp0 |"); $|=1; while(<P>){ print "------","$_"; }'
  2. save to a file echo "$cmd_perl" > "/tmp/"
  3. execute it in bash pointing file gnome-terminal -x bash -c 'perl /tmp/ >> /tmp/nethogs-dump-from-perl.hex '
    This method works fine. I want to avoid the use of temp file.

How to use echo command to show '? doesn't answer my question.

share|improve this question


bash -c "echo \'"


bash -c "echo \"'\""

Combining it:

$ bash -c 'echo "\"\\"'"\'"
share|improve this answer
case 1: Works OK but I want to print both ' and ". ie '" – totti Mar 18 '13 at 9:23
How about the 3rd example? The first part ( 'echo "\"\\"' ) uses single quotes, the second part ( "\'" ) uses double quotes. – Scrutinizer Mar 18 '13 at 9:26
case 2 : can only print ' – totti Mar 18 '13 at 9:35
case 3: terminal wait for something like end quote – totti Mar 18 '13 at 9:42
case 3: I think bash has access until bash -c 'echo "\"\\"'"\' and rest of the code ("\'" "\') not executed by bash. – totti Mar 18 '13 at 9:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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