0

I want to run two scripts at the same time. How exactly do I do this?

If I have a variable called foo in script1 and change its value to 5, and if I'm using a variable with the same name in script2 (that runs simultaneously with script1), will the value of variable foo in script2 also become 5?

2

You could run the first script in background like this:

skript1 & skript2

Each script will run as a separate process. You cannot change variables in the other script.

0

You can also open up two separate screen sessions to run both scripts. For example:

screen -S sampleOne
./runScript.sh

At that point you would hold CTRL+A&D, which will exit the screen without terminating and then type:

screen -S sampleTwo
./runScript2.sh

One other way would be to use tmux to do this as well:

tmux new-window -a -n SampleWindows
tmux new-session -d -s SampleWindows -n SSH0 -d
tmux selectp -t SampleWindows
tmux bind-key -n M-Left previous-window -t SampleWindows
tmux bind-key -n M-Right next-window -t SampleWindows
tmux new-window -n sampleOne -t SampleWindows
tmux new-window -n sampleTwo -t SampleWindows
tmux send-keys -t SampleWindows:0 './sampleScript' C-m
tmux send-keys -t SampleWindows:1 './sampleScript2.sh' C-m
tmux attach -t WinSplit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.