The tag has no wiki summary.

learn more… | top users | synonyms

69
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 ...
48
votes
12answers
16k 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?
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 ...
16
votes
9answers
1k views

How to make sure that a command is not interrupted, even if terminal is closed? [duplicate]

In Linux. Say I want to run a command and it takes too long. I just want to ensure it's done. How?
14
votes
2answers
534 views

Why does `exit &` not work?

I don't understand why exit & does not work. Why does it not?
12
votes
3answers
1k 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 ...
9
votes
3answers
1k 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 ...
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 ...
7
votes
5answers
174 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
6answers
17k 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 ...
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 ...
6
votes
1answer
104 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 ...
5
votes
4answers
996 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 ...
5
votes
1answer
261 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 ...
5
votes
3answers
508 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 ...
5
votes
1answer
218 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. ...
5
votes
3answers
925 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 ...
4
votes
2answers
8k 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: ...
4
votes
1answer
98 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 ...
4
votes
2answers
152 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
318 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, ...
3
votes
1answer
610 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 ...
3
votes
1answer
251 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
2answers
468 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 ...
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.
3
votes
2answers
277 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]$ ...
3
votes
1answer
415 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 ...
3
votes
3answers
851 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" == ...
3
votes
1answer
440 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 ...
3
votes
2answers
789 views

test if return true if grep on output has string in one line

I just want to return true or false if a service is running. Here is where I'm at, not first try or last but current at writing: service iptables status | grep -qi "not running" The sdtout for ...
3
votes
1answer
159 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 ...
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 ...
3
votes
0answers
226 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 ...
2
votes
5answers
2k views

What does exit 99 means?

I'm new to Unix. Just want to know what is exit 99 and why would one use it and what are the significance uses of it. For example, I'm using exit 99.
2
votes
3answers
362 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 = ...
2
votes
1answer
280 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 ...
2
votes
3answers
361 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 ...
2
votes
3answers
754 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?
2
votes
2answers
453 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 ...
2
votes
2answers
745 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 ...
2
votes
1answer
30 views

What signal does X send to its clients when it receives SIGINT?

If I terminate the Xorg server with a SIGINT signal (eg. when I press Ctrl+C), what signal does it send to its clients?
2
votes
3answers
84 views

Get exit status of a process over SSH

Not sure how to google this (I tried with some things and didn't get much) or how this is even called. This is my typical workflow: SSH to a server run something there and leave it running in ...
2
votes
2answers
114 views

Why does procmail send a copy of an inbound message to sender if it encounters an exit code?

I have a very simple procmail process that takes an inbound email and redirects it to a script: LOGFILE=/home/foo/procmail-log VERBOSE=yes MAILDIR=/var/spool/mail/foo DEFAULT=/var/spool/mail/foo ...
2
votes
1answer
129 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?
2
votes
1answer
54 views

more command behavior

Someone can explain me about the more command? when I use it with || or with &&, it seems to have an exist status of true, even when the file is not found(Unlike the other commands). ...
2
votes
2answers
517 views

Busybox ash script does not exit cleanly after executing cat; unable to get exit code

Consider the following script wrapcat.sh (a wrapper for cat) for illustrative purposes. It is run with busybox (ash) in an embedded Linux 2.6 box. #!/bin/sh cat $1 Under certain circumstances, this ...
2
votes
2answers
107 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? ...
2
votes
2answers
986 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 ...
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 ...
1
vote
1answer
38 views

How can I return a specific error code at this point in my TCL script?

I have a TCL expect script that runs a scp command for uploading a config file to my DNS server: #!/usr/bin/expect -f set config "~/dnsmasq.conf" spawn /usr/bin/scp "$config" ...