Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a shell script in new terminal from current terminal

How do you run a shell script in a new terminal in Linux from a terminal like "start test.bat" in Windows, also it should be working in the console mode.

like image 380
mreaevnia Avatar asked Nov 30 '12 16:11

mreaevnia


People also ask

How do I run a new terminal in Ubuntu?

Press and hold Ctrl first and then press Alt key and hold on to it as well. When you are holding both Ctrl and Alt keys, press T and you'll see that a new terminal window is opened.


2 Answers

Here's a simple example to get you started:

To write a shell script, do this on your command prompt:

echo -e '#!/bin/sh\n echo "hello world"' > abc.sh 

This writes:

#!/bin/sh echo "hello world" 

To a file called abc.sh

Next, you want to set it to executable by:

chmod +x abc.sh 

Now, you can run it by:

./abc.sh 

And you should see:

hello world 

On your terminal.

To run it in a new terminal, you can do:

gnome-terminal -x ./abc.sh 

or, if it's xterm:

xterm -e ./abc.sh 

Here's a list of different terminal emulators.

Alternatively, you just run it in your current terminal, but background it instead by:

./abc.sh & 
like image 57
sampson-chen Avatar answered Sep 19 '22 14:09

sampson-chen


I came here wanting to figure out how to make a script spawn a terminal and run it self in it, so for those who want to do that I figured out this solution:

if [ ! -t 0 ]; then # script is executed outside the terminal?   # execute the script inside a terminal window with same arguments   x-terminal-emulator -e "$0" "$@"   # and abort running the rest of it   exit 0 fi 
like image 34
Joakim L. Christiansen Avatar answered Sep 18 '22 14:09

Joakim L. Christiansen