[SOLVED] Run commands inside a terminal opened from a terminal....
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Run commands inside a terminal opened from a terminal....
Code:
gnome-terminal ; ls
gnome-terminal && ls
gnome-terminal > ls
The connectors here always execute 'ls' in the original terminal, not the new terminal. How can I force the ls command to execute inside the new terminal?
Thanks!
Last edited by charlemagne-is-my-son; 06-16-2014 at 06:53 AM.
just read the man page of gnome-terminal, it is the first switch: -e or -x can be used: gnome-terminal -e ls
the only problem the terminal will be closed as soon as your command completed, therefore you will not be able to see the result.
If you want to keep that terminal open you need to white a script...
gnome-terminal -e cd ~/Music/my-music/ && ls *.txt *.ogg && sleep 20s
New terminal opens with a red ribbon at the top saying "There was an error creating the child process for this terminal" and "Failed to execute child process 'cd' (no such file or directory)"
yes, because the command you entered cannot be executed directly. That's why you need to put it into a script and you need to execute that script by that -e.
gnome-terminal -e cd ~/Music/my-music/ && ls *.txt *.ogg && sleep 20s
New terminal opens with a red ribbon at the top saying "There was an error creating the child process for this terminal" and "Failed to execute child process 'cd' (no such file or directory)"
Almost right. The problem is insufficient quoting:
The -e takes only one parameter - a string to be interpreted.
bash -c requires the sequence of commands to be a string (remember, the first level quoting has been removed by the shell already), thus another level of quoting (here, using the " character).
You can also accomplish this by escaping the nested quotes, but it gets tricky to count the number of levels you go - and each time the string gets evaluated (or the remaining parts of the string) you have to add another level of escapes...
this is why it is easier to put the sequence of commands in a script, make it executable, then you can reference that script as the command to interpret.
Your script works like gang busters, but my script is still not working.
First, I want to switch to a fresh work station, so wmctrl -s 2
in this new station, I want a new terminal opened
I want this new terminal to run a bunch of programs. This is what I've got as an alias command:
Code:
alias muse='wmctrl -s 2 && gnome-terminal -e 'bash -c "ls ~/Music/my-music/project-files/*.aup" && "ls ~/Music/my-music/*.txt" && "echo "What song do you want to open?"" && "read name" && "gnome-open /home/matt/Music/my-music/audacity-notes.txt" && "gnome-open /home/matt/Music/my-music/$name.txt" && "audacity /home/matt/Music/my-music/project-files/$name.aup"''
but I get this:
Code:
bash: alias: -c: not found
bash: alias: ls ~/Music/my-music/project-files/*.aup: not found
Your script works like gang busters, but my script is still not working.
First, I want to switch to a fresh work station, so wmctrl -s 2
in this new station, I want a new terminal opened
I want this new terminal to run a bunch of programs. This is what I've got as an alias command:
Code:
alias muse='wmctrl -s 2 && gnome-terminal -e 'bash -c "ls ~/Music/my-music/project-files/*.aup" && "ls ~/Music/my-music/*.txt" && "echo "What song do you want to open?"" && "read name" && "gnome-open /home/matt/Music/my-music/audacity-notes.txt" && "gnome-open /home/matt/Music/my-music/$name.txt" && "audacity /home/matt/Music/my-music/project-files/$name.aup"''
but I get this:
Code:
bash: alias: -c: not found
bash: alias: ls ~/Music/my-music/project-files/*.aup: not found
Now you have too many quotes...
the -c option of bash takes a single string. what you have is 4 strings separated by && - which breaks the sequence for gnome terminal... Only the first string would be passed to bash.
the sequence you are trying to pass is:
Code:
"ls ~/Music/my-music/project-files/*.aup" && "ls ~/Music/my-music/*.txt" && "echo "What song do you want to open?"" && "read name" && "gnome-open /home/matt/Music/my-music/audacity-notes.txt" && "gnome-open /home/matt/Music/my-music/$name.txt" && "audacity /home/matt/Music/my-music/project-files/$name.aup"
Yet the string sent to bash is "ls ~/Music/my-music/project-files/*.aup". After that it is wrong.
What you have to have instead is:
Code:
"ls ~/Music/my-music/project-files/*.aup && ls ~/Music/my-music/*.txt && echo \"What song do you want to open?\" && read name && gnome-open /home/matt/Music/my-music/audacity-notes.txt && gnome-open /home/matt/Music/my-music/$name.txt && audacity /home/matt/Music/my-music/project-files/$name.aup"
Which is why it would be easier to make a script (I'm going to call it "playscript.sh":
Code:
#!/bin/bash
ls ~/Music/my-music/project-files/*.aup
ls ~/Music/my-music/*.txt
echo "What song do you want to open?"
read name
gnome-open /home/matt/Music/my-music/audacity-notes.txt
gnome-open /home/matt/Music/my-music/$name.txt
audacity /home/matt/Music/my-music/project-files/$name.aup
Then you can invoke it as:
[code]
gnome-terminal -e <path to script>/playscript.sh
I can understand your attempt at creating an alias for this... but your quoting is again slipping-
Code:
alias muse='wmctrl -s 2 && gnome-terminal -e '
is what you are creating an alis of... after that, it has mismatched quotes. Again, it is MUCH easier to get the quoting right when you keep things as simple as possible.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.