How to properly write and execute a shell script and exit correctly? [duplicate]
Clash 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?
linux shell-script shell command-line gnome-terminal
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.
|
show 1 more comment
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?
linux shell-script shell command-line gnome-terminal
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 runps
? Have you typed “Enter”? See this. But, really, runps
and see what (if anything) is running in that terminal.
– G-Man
yesterday
|
show 1 more comment
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?
linux shell-script shell command-line gnome-terminal
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
linux shell-script shell command-line gnome-terminal
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 runps
? Have you typed “Enter”? See this. But, really, runps
and see what (if anything) is running in that terminal.
– G-Man
yesterday
|
show 1 more comment
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 runps
? Have you typed “Enter”? See this. But, really, runps
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
|
show 1 more comment
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
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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, runps
and see what (if anything) is running in that terminal.– G-Man
yesterday