9

Via a bash command, I want open a terminal and, from the new terminal, execute a simple bash command.

I tried:

gnome-terminal -- "/bin/bash -c ls"

But I got this error:

enter image description here

I don't understand the error and I cannot find an example anywhere for help.

Islay
  • 478
  • 4
  • 17
spacecodeur
  • 2,206
  • 7
  • 35
  • 71
  • Use the `-e` option. It's taking that command as the name of a program to run, not a shell command to execute. – Barmar Feb 05 '18 at 17:19
  • SO is for programming questions, not questions about using or configuring Linux and its applications. SuperUser.com or unix.stackexchange.com would be better places for questions like this. – Barmar Feb 05 '18 at 17:19
  • 1
    -e arg is deprecied :/ ('Option “-e” is deprecated and might be removed in a later version of gnome-terminal.'). Nothing work when I use -e option, I get just the "deprecated" message – spacecodeur Feb 05 '18 at 17:21
  • 1
    `gnome-terminal -- /bin/bash -c ls`. No quotes. – Charles Duffy Feb 05 '18 at 17:21
  • nothing happen when I don't use quotes, no error, no new terminal, nothing – spacecodeur Feb 05 '18 at 17:22
  • 1
    Probably because it's exiting immediately. Try instead, say, `gnome-terminal -- /bin/bash -c 'ls; sleep 3'` – Charles Duffy Feb 05 '18 at 17:22
  • BTW, this has already been asked and answered here before. Give me a minute to find the duplicate to close the question... – Charles Duffy Feb 05 '18 at 17:24
  • hannn your right ! its work ! is there a way for 'keep' alive the new terminal after the command ? – spacecodeur Feb 05 '18 at 17:24
  • Give it any command that waits indefinitely without exit. – Charles Duffy Feb 05 '18 at 17:25
  • ok =) thank you a lot ! – spacecodeur Feb 05 '18 at 17:26
  • Ahh -- the other question I was thinking about was https://stackoverflow.com/questions/48236537/send-a-sequence-of-commands-to-a-new-terminal-from-a-script, but while the answer covers some similar ground, it's not quite a duplicate. – Charles Duffy Feb 05 '18 at 17:31

1 Answers1

16

The quotes are telling the terminal to run an executable in /bin called bash -c ls (with the spaces as part of its name!). There exists no such executable.

Take them out:

gnome-terminal -- /bin/bash -c ls

...or, to actually make something stay open until the user provides input...

gnome-terminal -- /bin/bash -c 'ls; read'
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • thank you :) as I ask from comment , is there a way for keep alive the new terminal regardless the command executed ? – spacecodeur Feb 05 '18 at 17:26
  • 1
    On a GNU system, you could run `sleep infinity` as the final command. More portably, though, I'd expect that `sleep $(( 60 * 60 * 24 * 365 ))` (to sleep for a year) would probably be good enough. – Charles Duffy Feb 05 '18 at 17:26
  • 2
    You can try gnome-terminal -- /bin/bash -c 'ls;exec /bin/bash' – ctac_ Feb 05 '18 at 19:06