[SOLVED] How do I run a command on a separate terminal in a bash script?
Hello World!
I'm trying to do something here:: I'm writing a bash script, I want to [open a new terminal and run a bash command in it] inside the script. I tried to use this, but apparently I get syntax errors. Quote:
|
Quote:
Still if you are trying to do so, an alternative is to run your script "Second.sh" through ssh. You can do something like: Code:
#! /bin/bash |
The script gets created as '~/Something.sh' but executed as './Something.sh', which would only be correct if the current working directory is '~/' I see no syntax error, however the script is so short that it closes the window almost immediately. If you do something more like
Code:
echo "echo Something; sleep 3" > ~/Second.sh --- rod. |
That was not what I wanted to do, I want my script to open a whole new shell console and start running my second script on that console. Like the main script is a root which triggers several sub-scripts to start running, each on a new shell console, Separately, and my main all my main terminal does would be creating the sub-scripts not running them.
|
Quote:
You're creating ~/Second.sh but executing ./Second.sh. What if the working directory is not $HOME? |
What exactly do you mean by 'a whole new shell console'? When you make the changes I previously suggested, what does it do or not do that you see as incorrect?
--- rod. |
That's not the problem, That was just an example of what I wanted in a nutshell,
you add a cd up there; |
Quote:
Does it solve your problem ? |
Yes I did. And No it didn't. (Thanks though :D)
Logically when I SSH to my local host, I'm using the VERY TERMINAL I'M USING to run my program. |
Quote:
|
Quote:
--- rod. |
Code:
echo 'echo "test";sleep 3' > testscript.sh; chmod u+x testscript.sh; xterm -e sh -c ./testscript.sh |
Since your script is writing a script, you also need to write the shebang to the script:
Code:
#! /bin/bash |
Quote:
xterm is told what to interpret it with in the -e option. If you don't specify it, it assumes the shell. EDIT: looking at the xterm man page, I found a problem! it says: Quote:
|
It is the last argument. Everything following the '-e' is considered part of that argument (at least in the examples here). Although there are elements within it that look like option arguments, they are for the command which will be launched by xterm, and are considered to be lumped together as part of the '-e' argument to xterm. I usually enclose the whole thing in quotes to enforce this, although evidently, this is not required.
--- rod. |
All times are GMT -5. The time now is 06:11 PM. |