2

I'm looking to run two independent parallel gnome-terminal windows with some parameters, from one shell script.

So far I've got this:

#!/bin/sh
gnome-terminal -e window1.sh &
gnome-terminal -e window2.sh &
exit

However, upon running this, the screens flash up and disappear. I was expecting both to appear, wait for key input, then continue working as normal terminal windows would, i.e., I should be able to continue typing commands into them both.

Here's the code for window1.sh + window2.sh:

#!/bin/sh
echo window 
read -p "press any key to continue"

I don't understand why they aren't even respecting the 'read' and waiting for input.

  • I tested with konsole I added --noclose option. I get this output window\n press any key to continue/home/richard/trash/term-test: 3: read: arg count – ctrl-alt-delor Aug 4 '15 at 8:44
  • 1
    Run unit tests. If you had tested window1.sh on its own, then you would realise that it is this script that is at fault. – ctrl-alt-delor Aug 4 '15 at 8:48
  • Hi Richard, I've done exactly that and window1.sh works just fine. I don't get the same output as you. I literally just get 'press any key to continue'. I don't get all the extra stuff. – Jay Aug 4 '15 at 8:57
  • What then happens when you press a key? – ctrl-alt-delor Aug 4 '15 at 8:58
  • 3
    Note using a file extension on scripts in non-Unix: it stops polymorphism. That is, it makes the caller dependant on the implementation e.g. if you change the implementation, to python, or C, then would you change the file extension. If so you have to change every program that uses your program/script. – ctrl-alt-delor Aug 4 '15 at 9:09
3

Run the script on its own.

./window1.sh

You will get this output.

window
press any key to continue./window1.sh: 3: read: arg count

This is because read is a bash command, but not a sh command.

  • Hey Richard, Thanks for your time. I don't get the same output as you. I only get "window" followed by "press any key to continue" - I don't get the 'term-test' bit – Jay Aug 4 '15 at 8:52
  • @user1203297: Is /bin/sh bash or dash on your system? Probably bash on yours, dash on Richard's. – Peter Cordes Aug 4 '15 at 8:58
  • It's bash on mine – Jay Aug 4 '15 at 9:02
  • My sh is dash I changed window1.sh to use bash then, ran konsole -e window1.sh. It worked good. I got a window it displayed the 2 lines of text I pressed Enter (the only key), and the window closed. – ctrl-alt-delor Aug 4 '15 at 9:03
  • Could you try with gnome-terminal please? – Jay Aug 4 '15 at 9:05
1

Are the scripts executable and in your $PATH? You probably need

gnome-terminal -e ./window1.sh &

Also, if the scripts are similar, write it once and pass a parameter as an argument:

gnome-terminal -e ./window.sh 1 &
gnome-terminal -e ./window.sh 2 &

"$@" expands to the command line args, each quoted separately. "$1" is the first arg, etc. etc.

  • 1
    It this scenario using konsole --noclose I get a nice error: Warning: Could not find '/home/richard/…/window1.sh'', starting '/bin/bash' instead. Please check your profile settings. – ctrl-alt-delor Aug 4 '15 at 9:06
  • Thanks Peter. The scripts are similar for this POC - but I'm going to be expanding them into very different scripts at a later date with different names. So unfortunately I can't pass the numbers as a parameter. I've tried to use absolute paths too - but it hasn't helped. – Jay Aug 4 '15 at 9:07

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.