Score:1

How can I exit the entire script if

cn flag

How to stop a script if it has been run using bash test.sh or ./test.sh?

# if the script was run with bash test.sh or ./test.sh, stop

echo "From here the script only works if it has been run with source test.sh or . test.sh"
hr flag
See [How to define a shell script to be sourced not run](https://unix.stackexchange.com/questions/424492/how-to-define-a-shell-script-to-be-sourced-not-run)
cn flag
Perfect! That's exactly what I needed!
Score:-2
sn flag

ctrl+c if it was not send in background. if it is in background then run
ps aux | grep test.sh
then grab the process id from the PID column
then use the kill to stop it. so if the PID is 3946 for example. run
kill 3946

then run again
ps aux | grep test.sh
and if the only result you get is your grep then the process has stopped. Else you might need to force it with the
kill -9 3946
that a bit more brutal but use as last resort.
you can run
kill -l
that will give you the list of signal you can send to the process with the kill command

cheers

raj avatar
cn flag
raj
This is not understandable. Please clarify.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.