0

I wrote a shell script that calls some other shell scripts in a new terminal window. It was working fine on my computer. its like this

#!/bin/sh
gnome-terminal -e "sh one.sh"
zenity --info --text "exed one"
gnome-terminal -e "sh 2.sh"
zenity --info --text "exed 2"
firefox "www.aurl1.com" "www.aurl2.com"

According what I understood, the script will first open a terminal and run the first script, after finishing that it will show the zenity then run two in new terminal then show zenity like that. But when the same was exed on another computer, the script is not following this order. It simply opens all terminal side by side not waiting one to finish and showing the dialogues together. Why is this problem ? Thanks in advance.

Xander
  • 1,652
  • 2
  • 15
  • 20
  • "But when the same was exed on another computer" (it didn't work). Are you absolutely sure that the `#!/bin/sh` is the same on both machines. Consider editing your question with the output of `uname -a` from both computers, if you find a difference. Good luck. – shellter Jun 06 '12 at 03:28
  • yes #!/bin/sh is same on both machines, installed from same iso. – Xander Jun 06 '12 at 04:36
  • Also I installed this on a Virtual machine that have same iso of these... The script is showing same issue there too.. – Xander Jun 08 '12 at 04:36

2 Answers2

1

It used to be that gnome-terminal would run each terminal in its own process. But now gnome-terminal checks on startup if there is already a gnome-terminal process running, and if so, tells the existing terminal process to open a new window with the given arguments. There is no problem with your script: it is waiting for each process to finish in turn, it is just that gnome-terminal is exiting immediately after passing off its work to a different process.

According to man gnome-terminal, you can use the --disable-factory option to disable this behaviour, and run each command in its own process.

Try this:

gnome-terminal --disable-factory -e 'sh -c "echo hi && sleep 10"'
echo now you can run script 2
andrewdotn
  • 32,721
  • 10
  • 101
  • 130
0

Run them like this:

gnome-terminal -e "sh one.sh" ; zenity --info --text "exed one" ; gnome-terminal -e "sh 2.sh" ; zenity --info --text "exed 2"

What the comma does is it tells the shell to execute the first command, wait for it to finish and only then move on to the next. Otherwise, the behavior you described is normal, it parses the lines one by one, without waiting for anything.

AlexT
  • 1,145
  • 10
  • 11
  • It didnt work means, I wrote a script similar to the one I gave above, The script is supposed to first execute the first statement, wait that to finish, then execute the second statement, then the third after the second is finished... but it is not working that way.. The first script is started, then the second is started without finishing the first.. the third is started without second being finished.. No matter on giving the semi colon – Xander Jun 11 '12 at 06:33
  • I have gave the command firefox "" "" in the script, this should open only when all the statements above that is finished. But, as just the script is run, firefox will open up. – Xander Jun 11 '12 at 06:34
  • Did you put everything on the same line, with semicolons in between, like I suggested? (except for the shebang - `#!/bin/sh` - which should be on it's own, on the first line). Or are they still on separate lines, with a semicolon at the end? – AlexT Jun 12 '12 at 02:29
  • No, am sure about those stuff because, I mentioned, it is working excellent on my computer – Xander Jun 12 '12 at 06:18