1
vote
1answer
34 views

How do I get the exit code of a process, which runs through wine

I'm trying to run a Windows executable via wine. When I first try to run it never runs, but when I attempt to do it again, the program runs. I'd like to make a script to run the program, here's the ...
2
votes
3answers
131 views

Should I embed a command in a conditional or test its return code?

It's a simple question of best pratices: Which should I use? Option 1 ping -c1 "$host" if [[ $? -eq 0 ]] ; then command else command fi Option 2 if ping -c1 "$host" ; then command ...
0
votes
2answers
46 views

Determining the exit status of the “return” built-in

I was reading about traps, but only return works for me in my shell script, so was wondering what status or code it returns, so what I tried is, #!/bin/bash seeOutput=`return` echo $seeOutput It's ...
1
vote
1answer
34 views

'script' session logging makes me exit twice

I'm using a solution described here to log my shell sessions, by adding this to the end of /etc/bash.bashrc: test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f ...
0
votes
2answers
316 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}" ...
2
votes
3answers
1k views

How to copy or read the return value (exit status) from AWK script into the shell script (bash) to be used in if statement to compare

I want to read the error codes or the exit status of awk script into shell to use in if condition to compare for error handling my shell script looks something like: My script: #!/bin/sh awk -v ...
7
votes
1answer
134 views

How do I capture the exit code / handle errors correctly when using process substitution?

I have a script that parses file names into an array using the following method taken from a Q&A on SO: unset ARGS ARGID="1" while IFS= read -r -d $'\0' FILE; do ARGS[ARGID++]="$FILE" done ...
3
votes
1answer
512 views

Unable to get the right exit code from a script

I have a script which connects to a remote server via SFTP and get some file from there. My script goes like this: /usr/bin/sftp USER@remote.server.com <<EOF lcd /dir1/dir2/dir3 cd ...
3
votes
0answers
648 views

Proper usage of EXIT & ERR traps in bash scripts [closed]

I'm working on a bash script and as I've been going I've learned about traps, signals, function return codes and other such features I've not previously used. I may be thinking about things ...
1
vote
1answer
2k views

How to exit out of the shell script successfully so that python subprocess think it is successfull exit? [closed]

Below is my shell script which simply execute a url like this http://example.com:8080/beat and parse the response and verify certain conditions on it. If that condition is met, then exit successfully ...
7
votes
5answers
207 views

Can a program next in a pipeline see the exit code of the previous program?

I would like to make a pipeline of Bash scripts like this prog1 | prog2 such that prog2 can see the exit code of prog1 and act differently based on that information. Is this possible?
6
votes
3answers
2k 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
217 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 ...
3
votes
2answers
721 views

What is “Exit 2” from finished background job status?

I have an exercise to put in a file some data (*conf from some directories) and need to do this in background. I did it and I am wondering what is the meaning of output messages: [A@localhost tests]$ ...
0
votes
2answers
262 views

Test if number from range <0,infinity)

I have a problem If [[ * ]] then continue else exit 1 fi I want to test that the argument to my switch (for example -d 3) is a valid positive decimal integer number (a sequence of one or more of ...
2
votes
1answer
186 views

How to have a bash script perform a specific action on errors of _each_ command?

Similarly to set -e performs an exit on "uncaught" $? != 0, I'd like to have this event trigger the execution of another command, e.g. a logger call. How can this be done?
72
votes
4answers
1k views

Can I somehow add a “&& prog2” to an already running prog1?

Most shells provide functions like && and ; to chain the execution of commands in certain ways. But what if a command is already running, can I still somehow add another command to be executed ...
3
votes
1answer
602 views

How to trick an init script into returning 0

I have a init script which is poorly designed because it does not conform to the Linux Standard Base Specifications The following should have an exit code of 0 if running, and 3 if not running ...
12
votes
3answers
2k views

Wait command usage in Linux?

#!/bin/bash function back() { sleep $1 exit $2 } back $1 $2 & b=$! if `wait $!`;then echo success else echo failure fi bash-3.00# ./back 300 0 failure bash-3.00# ./back 300 1 ...
0
votes
2answers
2k views

Expect script within bash & exit codes

I have a bash script that calls an expect script. The expect script has several conditions. It ssh's into a box and executes a command, and there are different possible errors that could happen which ...
1
vote
0answers
2k 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) ...
5
votes
3answers
669 views

bash -e exits when let or expr evaluates to 0

I have a bash script that sets -e so the script will exit on any exit status != 0. I'm trying to do some basic shell arithmetic assigned to variables and sometimes the expression equals 0 which ...
2
votes
1answer
327 views

Exit status ($?) of 148 upon Ctrl+Z

I just customized my .bashrc to include the exit status of the last command, so I get fancy prompts like ☑ larsmans@host:~$ and I no longer have to re-run commands to see their exit status because ...
3
votes
1answer
1k views

Why won't my bash script exit after execution?

I compiled a short bash one-liner to focus a running application or launch it if it isn't running: #!/bin/bash #intellilaunch.sh wmctrl -a $1 || $1 & disown exit 1 The command exits perfectly ...
2
votes
2answers
109 views

Are any files loaded when a terminal session terminates?

I know that .profile / .bash_profile are loaded when a terminal session is started, either through local machine or SSH. Are there any files that are loaded/called when the session terminates? ...
3
votes
2answers
399 views

How to write an abort-on-error script without adding `|| exit $?` to every line?

I'm writing a bash script that should exit the error code of the last failed command and not continue execution. This can be achieved by adding a || exit $? everywhere, but is there an easier way, ...
5
votes
1answer
306 views

How does sh -e interact with &?

I'm using sh (dash) on Ubuntu (lucid) and the manpage has this to say about -e: -e errexit If not interactive, exit immediately if any untested command fails. ...
3
votes
2answers
575 views

How to use $? and test to check function?

#!/bin/sh function checkExit(){ if test "$?" != "0"; then echo Command $1 exited with abnormal status exit 1; else echo $? fi } function echoThenRun () { # echo and then ...
2
votes
2answers
497 views

.DELETE_ON_ERROR behavior with make and pipelines

The .DELETE_ON_ERROR target will tell make to delete a target if a rule fails. But this doesn't work for pipelines, because the exit status value $? holds the value of the last program in the ...