LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 06-16-2014, 06:50 AM   #1
charlemagne-is-my-son
Member
 
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54

Rep: Reputation: Disabled
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.
 
Old 06-16-2014, 07:00 AM   #2
jamison20000e
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
Blog Entries: 2

Rep: Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567
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
 
Old 06-16-2014, 07:17 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,021

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
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.
Old 06-16-2014, 08:32 AM   #4
charlemagne-is-my-son
Member
 
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54

Original Poster
Rep: Reputation: Disabled
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)"
 
Old 06-16-2014, 08:35 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,021

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
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.
Old 06-16-2014, 08:50 AM   #6
charlemagne-is-my-son
Member
 
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54

Original Poster
Rep: Reputation: Disabled
Thumbs up oh!

Hmmm I'm still getting an error. I'm screwing something up.

I try
Code:
bash /home/test.sh
test.sh is

Code:
gnome-terminal -e echo luck
and I get

Code:
Failed to parse arguments: Unknown option -r
in the new terminal
 
Old 06-16-2014, 08:53 AM   #7
charlemagne-is-my-son
Member
 
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54

Original Poster
Rep: Reputation: Disabled
-r

Also tried running the script after -e

Code:
gnome-terminal -e bash /home/test.sh
same problem
 
Old 06-16-2014, 10:09 AM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by charlemagne-is-my-son View Post
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.
Old 06-16-2014, 10:36 AM   #9
charlemagne-is-my-son
Member
 
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54

Original Poster
Rep: Reputation: Disabled
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
 
Old 06-16-2014, 11:50 AM   #10
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by charlemagne-is-my-son View Post
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.
 
Old 06-16-2014, 12:38 PM   #11
charlemagne-is-my-son
Member
 
Registered: Dec 2012
Location: Shanghai
Distribution: Xubuntu, 14.04
Posts: 54

Original Poster
Rep: Reputation: Disabled
mission accomplished

Thanks. I got it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Run commands from a new terminal in a script shubham.joy Linux - Newbie 3 03-31-2014 12:44 AM
[SOLVED] make a script that opens a specific terminal and enter commands into that terminal jejuba Linux - General 2 11-10-2013 01:43 PM
problem run script inside a gnome-terminal jao_madn Programming 5 06-23-2012 03:26 PM
Not sure how to run terminal commands at startup mandrakethepenguin Linux - Newbie 4 01-04-2006 08:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration