-1

I have written a shell script named startup.sh which does a lot of things (basically start a lot of things for me after turning on my local machine) - here is an excerpt:

#!/bin/bash
gnome-terminal --tab &
veracrypt --auto-mount favorites &
thunderbird &
~/Application/IDEA/bin/./idea.sh &
/usr/bin/slack &
echo myuser mypass | skypeforlinux --pipelogin &
sh bsync-project-folder.sh &
exit

Open a console window and do:

. startup.sh

The shell script is executed and the window is closed afterwards.

Also working:

sh startup.sh

OR

./startup.sh

The shell script is executed and the terminal window stays open - however it does not return to the console and have to stop script execution with CTRL + C (no matter if I execute with the command line interpreter or with ./).

However I want a clean exit of my script and then return to the same console with a success message. What am I missing?

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Blackbam
  • 191
  • 1
  • 1
  • 10
  • Check out [What is the difference between executing a Bash script vs sourcing it?](https://superuser.com/q/176783/942947). – francescop21 Nov 14 '18 at 13:28
  • Also, possible duplicate of [What is the difference between sourcing ('.' or 'source') and executing a file in bash?](https://unix.stackexchange.com/q/43882/310237). – francescop21 Nov 14 '18 at 13:30
  • Does the veracrypt command return you to the prompt if you run it interactively? Also, you say it's an excerpted script; you may not have posted the offending line-- look for one that does not end in `&` – Jeff Schaller Nov 14 '18 at 13:32
  • @JeffSchaller Have added the full script and also without Veracrypt it does not stop executing. – Blackbam Nov 14 '18 at 13:34
  • I hate to insult your intelligence, but, … you say “it does not return to the console and [I] have to stop script execution with Ctrl + C …”  How do you know it hasn’t returned?  Have you run ``ps``?  *Have you typed “Enter”?* See [this](https://unix.stackexchange.com/q/268230/80216 "Process list as a background process"). But, really, run `ps` and see what (if anything) is running in that terminal. – G-Man Says 'Reinstate Monica' Nov 14 '18 at 22:05
  • @G-Man This is a Q&A site and it is for experts as well as for beginners. I did not find an answer fast. Everybody has more or less knowledge depending on the topic. If there is already an answer to a question just mark the corresponding duplicate. – Blackbam Nov 14 '18 at 23:29

1 Answers1

1

When you start a script with '< dot> < space> < script_name>' and you have in your script "exit", your window will be closed. The dot notation means you run it within the window and then the "exit" means to exit the window, not the script itself.
Try to add >/dev/null 2>&1 to each of the line (before final &) to find out which of the commands still holds stdout, eg.:
gnome-terminal --tab >/dev/null 2>&1 &
...
you may but need not to leave the exit at the end but it does not have any sense here. Run the script: ./startup.sh

Michael
  • 38
  • 5
  • With `>/dev/null 2>&1` it turned out that intellij AND the second shell script were responsible for the script not to terminate properly. Thanks! – Blackbam Nov 14 '18 at 15:03