Linux - Software This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
06-16-2014, 06:50 AM
|
#1
|
Member
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54
Rep: 
|
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.
|
|
|
06-16-2014, 07:00 AM
|
#2
|
Senior Member
Registered: Nov 2005
Location: ...uncanny valley... infinity\1975; (randomly born:) Milwaukee, WI, US( + travel,) Earth&Mars (I wish,) END BORDER$!◣◢┌∩┐ Fe26-E,e...
Distribution: any GPL that work on freest-HW; has been KDE, CLI, Novena-SBC but open.. http://goo.gl/NqgqJx &c ;-)
Posts: 4,888
|
I'm sure someone will be along with an answer for you I know Ctrl+Shift+N opens a new Konsole for me but I don't know if Bash can do key strokes?
https://bbs.archlinux.org/viewtopic.php?id=133065
|
|
|
06-16-2014, 07:17 AM
|
#3
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,467
|
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...
|
|
1 members found this post helpful.
|
06-16-2014, 08:32 AM
|
#4
|
Member
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54
Original Poster
Rep: 
|
test script
Here is test.sh:
Code:
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)"
|
|
|
06-16-2014, 08:35 AM
|
#5
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,467
|
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.
|
|
1 members found this post helpful.
|
06-16-2014, 08:50 AM
|
#6
|
Member
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54
Original Poster
Rep: 
|
oh!
Hmmm I'm still getting an error. I'm screwing something up.
I try test.sh is
Code:
gnome-terminal -e echo luck
and I get
Code:
Failed to parse arguments: Unknown option -r
in the new terminal
|
|
|
06-16-2014, 08:53 AM
|
#7
|
Member
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54
Original Poster
Rep: 
|
-r
Also tried running the script after -e
Code:
gnome-terminal -e bash /home/test.sh
same problem
|
|
|
06-16-2014, 10:09 AM
|
#8
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
Quote:
Originally Posted by charlemagne-is-my-son
Here is test.sh:
Code:
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:
Code:
gnome-terminal -e 'bash -c "cd ~/Music/my-music/ && ls *.txt *.ogg && sleep 20s"'
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.
Last edited by jpollard; 06-16-2014 at 10:14 AM.
|
|
2 members found this post helpful.
|
06-16-2014, 10:36 AM
|
#9
|
Member
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54
Original Poster
Rep: 
|
Simple script works, but....
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
|
|
|
06-16-2014, 11:50 AM
|
#10
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
Quote:
Originally Posted by charlemagne-is-my-son
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.
Last edited by jpollard; 06-16-2014 at 11:52 AM.
|
|
|
06-16-2014, 12:38 PM
|
#11
|
Member
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54
Original Poster
Rep: 
|
mission accomplished
Thanks. I got it.
|
|
|
All times are GMT -5. The time now is 10:55 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|