1
vote
1answer
23 views

How do I obtain the kill signal / message / reason within a script?

I am using the following trap: trap OnExit EXIT And in my OnExit function I would like to capture all the info I can on what happened so I can write it to a log file. Id like to know who, why, how, ...
0
votes
2answers
81 views

Exit the bash function, not the terminal

I have a bash script as below which installs zookeeper but only if not installed already. ##zookeper installZook(){ ZOOK_VERSION="3.4.5" ZOOK_TOOL="zookeeper-${ZOOK_VERSION}" ...
5
votes
3answers
912 views

reliable return code of background process

Let's assume the following piece of bash code: foo > logfile 2>&1 & foo_pid=$! while ps -p$foo_pid do ping -c 1 localhost done wait $foo_pid if [[ $? == 0 ]] then echo "foo ...
0
votes
1answer
123 views

if env variable exists then exit out of script

#!/bin/bash if [[ -n "$MYVAR" ]]; then exit; fi # otherwise the rest of the script continues... I'm trying to exit out of a shell script if a certain ENV variable is 0. The script above does not ...
1
vote
0answers
1k views

Using sshpass, return code (exit status) differs for reasons unknown using valid commands

There are a few things going on here but I think ultimately, either CLish or SSH is returning an exit code that is messing up my work flow. I'm attempting to connect to a remote machine (CLish shell) ...
3
votes
3answers
850 views

What does exit do in an if block in a shell script?

I have a question regarding unix shell script. Say if you do exit 1 in inner if: will it exit or will it still execute the outer if? The following is a dummy example. if [ "$PASSWORD" == ...
6
votes
3answers
2k views

exit shell script from a subshell

Consider this snippet: stop () { echo "${1}" 1>&2 exit 1 } func () { if false; then echo "foo" else stop "something went wrong" fi } Normally when func ...
2
votes
3answers
361 views

Return value of commands when using stdin?

Imaging I am executing the following command: echo "root:mypass" | chpasswd How can I get the return code / error code returned by chpasswd? Is that possible in this case at all? I tried RET = ...
17
votes
1answer
488 views

Is there a standard command that always exits with a failure?

I want to test my script with a command that fails. I could use an existing command with bad arguments. I could also write a simple script that immediately exits with a failure. Both of these are easy ...
3
votes
2answers
2k views

Exit Google Chrome from terminal

Is there a way to cause google-chrome to quit, from the terminal, besides using killall google-chrome? I would like to be able to close it from a script without killing it.