The tag has no wiki summary.

learn more… | top users | synonyms

3
votes
3answers
1k 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" == ...
1
vote
2answers
675 views

Negate exit code without using shell features

Is there any standard command that will negate the the exit code of another command provided as an argument without using shell features, or starting a shell? I have a program that does something ...
3
votes
2answers
445 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
372 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. ...
8
votes
4answers
3k 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
415 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 = ...
3
votes
1answer
616 views

wait does not wait

If i have a file called myprogram containing sleep 200 date Run this in the background: $ sh myprogram & i want to know when myprogram has completed by using wait command $ cat >notify ...
18
votes
1answer
611 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
1answer
791 views

Evaluating the return value of a command line

How do I evaluate or calculate the return value of a command line? For exemple, I count the number of lines with a grep and I want to know if that value is above X. If so, I want to print the number ...
7
votes
6answers
25k views

exit out of all SSH connections in one command and close PuTTY

Is there a way to back out of all SSH connections and close PuTTY in "one shot"? I work in Windows 7 and use PuTTY to SSH to various Linux hosts. An example of the way I find myself working: SSH to ...
1
vote
2answers
1k views

How to pass data outside process for zenity progress?

Usually this would be a question about how to pass data from a subprocess to a main process, but maybe zenity has some extra quirks so please focus on zenity. Example: #!/bin/sh ( echo "10" ; sleep ...
4
votes
2answers
11k views

Why do I get error 255 when returning -1

I'm new into C++ programming and I have a very basic question. I've noticed that when I return -1 in C++ program and then check the exit status, I get 255. Why is that? The code is the most basic: ...
5
votes
4answers
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.
9
votes
3answers
2k views

Is it safe to close shell just by clicking “X” or using “ctrl+d”?

Is it safe to close shell just by clicking "X" or using "ctrl+d" while logged in as root with su or is it safer to close it by typing "exit"? Is there any difference (security-wise) at all or is it ...
4
votes
1answer
100 views

Is it the process that cleans itself on termination or the kernel?

Recently I found this in a powerpoint presentation: When a program is compiled and linked, the linker inserts some extra code in the program. It is this code that calls the main function about the ...
2
votes
3answers
928 views

What is meant with terminating a process normally?

In an examination it is stated: Give 2 different ways that a process can terminate normally. Describe the differences. What is meant with terminate normally?
3
votes
1answer
165 views

Testing equivalence for exit status

Are the following two command lists portably equivalent? $foo; echo $? #(1) and $foo && echo 0 || echo $? #(2) Postscript Consider the command exit-status defined so: #!/bin/sh exit ...
5
votes
1answer
332 views

Return value of a process and comparison of the number

I have a val.py python script that returns a negative number. import sys sys.exit(-1234) When I run this bash script, I get the value $? as return value of 46 (not -1234). Even when I tried to ...
4
votes
2answers
163 views

Unable to capture program exit

I started a program written using Node.js and started it using launch pipe into logfile and send it to background. Half way running the program exited w/o any error both on the console nor the log, I ...
3
votes
2answers
627 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
525 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 ...
3
votes
2answers
815 views

Removing zombie process from the process table

Can somebody please explain when parent process receives the exit status of a dead child process via wait, who actually reallocates the memory of the child process and removes it from the process ...
5
votes
4answers
1k views

Why can't I get the exit values of a command in this bash script?

So I was writing this little nautilus script for transcoding video into mp3: #! /bin/bash -x if [ -z "$1" ] then zenity --warning --text="Error - No file selected !" exit 1 fi ...
61
votes
12answers
23k views

Get exit status of process that's piped to another

I have two processes foo and bar, connected with a pipe: $ foo | bar bar always exits 0; I'm interested in the exit code of foo. Is there any way to get at it?
2
votes
2answers
1k views

dhclient exits with status 0 but still no address

I've been trying to find out with the man page and some other sources if the exit status doesn't necessarily mean you achieved an address but I'm thinking I maybe didn't read it correctly. Does anyone ...
8
votes
4answers
2k views

Why should a child of a vfork or fork call _exit() instead of exit()?

From the man page of vfork(): vfork() differs from fork() in that the parent is suspended until the child makes a call to execve(2) or _exit(2). The child shares all memory with its ...