How to properly write and execute a shell script and exit correctly? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite













This question already has an answer here:



  • Process list as a background process

    1 answer



  • What is the difference between sourcing ('.' or 'source') and executing a file in bash?

    4 answers



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?










share|improve this question















marked as duplicate by schily, Archemar, elbarna, G-Man, RalfFriedl 18 hours ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Check out What is the difference between executing a Bash script vs sourcing it?.
    – francescop21
    yesterday










  • Also, possible duplicate of What is the difference between sourcing ('.' or 'source') and executing a file in bash?.
    – francescop21
    yesterday










  • 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
    yesterday










  • @JeffSchaller Have added the full script and also without Veracrypt it does not stop executing.
    – Blackbam
    yesterday











  • 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. But, really, run ps and see what (if anything) is running in that terminal.
    – G-Man
    yesterday














up vote
-1
down vote

favorite













This question already has an answer here:



  • Process list as a background process

    1 answer



  • What is the difference between sourcing ('.' or 'source') and executing a file in bash?

    4 answers



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?










share|improve this question















marked as duplicate by schily, Archemar, elbarna, G-Man, RalfFriedl 18 hours ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Check out What is the difference between executing a Bash script vs sourcing it?.
    – francescop21
    yesterday










  • Also, possible duplicate of What is the difference between sourcing ('.' or 'source') and executing a file in bash?.
    – francescop21
    yesterday










  • 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
    yesterday










  • @JeffSchaller Have added the full script and also without Veracrypt it does not stop executing.
    – Blackbam
    yesterday











  • 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. But, really, run ps and see what (if anything) is running in that terminal.
    – G-Man
    yesterday












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question already has an answer here:



  • Process list as a background process

    1 answer



  • What is the difference between sourcing ('.' or 'source') and executing a file in bash?

    4 answers



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?










share|improve this question
















This question already has an answer here:



  • Process list as a background process

    1 answer



  • What is the difference between sourcing ('.' or 'source') and executing a file in bash?

    4 answers



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?





This question already has an answer here:



  • Process list as a background process

    1 answer



  • What is the difference between sourcing ('.' or 'source') and executing a file in bash?

    4 answers







linux shell-script shell command-line gnome-terminal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Rui F Ribeiro

38.1k1475123




38.1k1475123










asked yesterday









Blackbam

1118




1118




marked as duplicate by schily, Archemar, elbarna, G-Man, RalfFriedl 18 hours ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by schily, Archemar, elbarna, G-Man, RalfFriedl 18 hours ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • Check out What is the difference between executing a Bash script vs sourcing it?.
    – francescop21
    yesterday










  • Also, possible duplicate of What is the difference between sourcing ('.' or 'source') and executing a file in bash?.
    – francescop21
    yesterday










  • 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
    yesterday










  • @JeffSchaller Have added the full script and also without Veracrypt it does not stop executing.
    – Blackbam
    yesterday











  • 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. But, really, run ps and see what (if anything) is running in that terminal.
    – G-Man
    yesterday
















  • Check out What is the difference between executing a Bash script vs sourcing it?.
    – francescop21
    yesterday










  • Also, possible duplicate of What is the difference between sourcing ('.' or 'source') and executing a file in bash?.
    – francescop21
    yesterday










  • 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
    yesterday










  • @JeffSchaller Have added the full script and also without Veracrypt it does not stop executing.
    – Blackbam
    yesterday











  • 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. But, really, run ps and see what (if anything) is running in that terminal.
    – G-Man
    yesterday















Check out What is the difference between executing a Bash script vs sourcing it?.
– francescop21
yesterday




Check out What is the difference between executing a Bash script vs sourcing it?.
– francescop21
yesterday












Also, possible duplicate of What is the difference between sourcing ('.' or 'source') and executing a file in bash?.
– francescop21
yesterday




Also, possible duplicate of What is the difference between sourcing ('.' or 'source') and executing a file in bash?.
– francescop21
yesterday












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
yesterday




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
yesterday












@JeffSchaller Have added the full script and also without Veracrypt it does not stop executing.
– Blackbam
yesterday





@JeffSchaller Have added the full script and also without Veracrypt it does not stop executing.
– Blackbam
yesterday













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. But, really, run ps and see what (if anything) is running in that terminal.
– G-Man
yesterday




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. But, really, run ps and see what (if anything) is running in that terminal.
– G-Man
yesterday










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










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






share|improve this answer




















  • 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
    yesterday

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










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






share|improve this answer




















  • 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
    yesterday














up vote
1
down vote



accepted










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






share|improve this answer




















  • 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
    yesterday












up vote
1
down vote



accepted







up vote
1
down vote



accepted






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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Michael

334




334











  • 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
    yesterday
















  • 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
    yesterday















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
yesterday




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
yesterday


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay