Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [exit]

The tag has no usage guidance.

-1
votes
1answer
63 views

Is the term trap (of Bash) more accurate than the generic “callback” term in programming? [closed]

Please consider: scripttmp=$(mktemp -d) cleanup() { rm -rf "${scripttmp}" } trap cleanup EXIT I understand cleanup is a "call(ed)back" function as it's being called just before exiting from ...
0
votes
1answer
41 views

Does tmux kill-server shut down running applications gracefully?

Using the tmux command kill-server one can immediately shut down the tmux server and close all open tmux windows. How does this affect the processes still running inside the various tmux windows? Will ...
2
votes
2answers
193 views

How to remove “exit” command from Linux shell

I am working on Linux Ubuntu 16.04. In this challenge I want to remove some commands from the Linux shell. Specifically, I want to remove the exit command. I want that if a user will try to exit ...
0
votes
0answers
19 views

Ending slogin session with exit command freezes due to PROMPT_COMMAND modification

I recently embedded an "alert" command into my PROMPT_COMMAND to give me a little notify-send screen notification with the exit code of each command (because I always forget to append the alert when a ...
10
votes
5answers
2k views

Capture exit code of exit command

I have this in a bash script: exit 3; exit_code="$?" if [[ "$exit_code" != "0" ]]; then echo -e "${r2g_magenta}Your r2g process is exiting with code $exit_code.${r2g_no_color}"; exit "$...
0
votes
1answer
282 views

How can I exit i3 without using a mouse?

Whenever I go to exit i3 a bar shows up on the top giving me the ability to to click Yes, to exit, or X to cancel.
-1
votes
2answers
36 views

Unable to terminate a running program / application

I am having trouble terminating applications started from the terminal - for example, I used: cd /usr/bin and ls to determine that the gimp app is here. I then started gimp by typing "gimp" - started ...
5
votes
1answer
500 views

What is the differences between “kill -PIPE $$” vs. “exit 1”?

In my Bash script, I used the following syntax in order to exit from the Bash script: kill -PIPE $$ I use it because sometimes in a function or in an internal shell in the script, the exit 1 does ...
0
votes
1answer
44 views

Error in grep command to exit from a Unix Script

I have a log file created while running a script. I want to check the same log file for any messages with 'Msg ....' and exit the code except with this 'Msg 2714'. So, I had added the below code ...
7
votes
1answer
651 views

exit not terminating the script [duplicate]

exit doesn't terminate the script when error is called.. output Error: Could not resolve localhost after exit script #!/bin/sh resolve_ip (){ if [ -z "$1" ]; then host="localhost" ...
10
votes
2answers
2k views

Why is vfork() intended to be used when the child process calls exec() or exit() immediately after creation?

Operating System Concepts and APUE say With vfork(), the parent process is suspended, and the child process uses the address space of the parent. Because vfork() does not use copy-on-write, if ...
2
votes
4answers
407 views

What exit modes exist in shell-scripting in general and in Bash in particular?

I know that in shell-scripting an "exit" usually means voluntarily or at least successfully terminating a session (or a process within a session) and that there are several different exit modes; the ...
2
votes
0answers
33 views

bash script does not exit on error even with -e option set [duplicate]

anyone know why this not works? I'v set -o errexit (same as -e), the following script should exit after executing the ID... statements. #!/bin/bash set -o errexit -o pipefail ID=$(ls any-non-exist-...
1
vote
1answer
62 views

how to get the stated behaviour for awk's system() command? [duplicate]

I'm calling the sleep command from awk like so: system("sleep 15m") and found that when I interrupt that with CTRL-C it only interrupts the sleep command, not the script. So I tried wrapping the ...
4
votes
3answers
425 views

How can I skip the rest of a script without exiting the invoking shell, when sourcing the script?

I have a bash script, where I call exit somewhere to skip the rest of the script when getopts doesn't recognize an option or doesn't find an expected option argument. while getopts ":t:" opt; do ...
1
vote
2answers
38 views

Using the value of a variable as an exit code from a script

I can find plenty of information about how to assign the exit code of a script to av variable, but I want to do the opposite: use the value of a variable (defined within a script) as the exit code of ...
0
votes
0answers
45 views

Variable assignment exit status

Normally, if has an exit status not zero, execution will continue: false echo 'this will show' If you use set -e, the shell immediately shall exit: set -e false echo 'this will not show' I am ...
0
votes
0answers
120 views

Escaping from stuck telnet session on MobaXterm

This is a follow-up to Quitting telnet on Linux As it turned out, MobaXterm gets in the way of escaping from a stuck telnet session using CTRL-5 on a Hungarian keyboard. Answer https://superuser....
0
votes
1answer
463 views

Quitting telnet on Linux

Standard escape character is CTRL-] on telnet. https://superuser.com/questions/398/how-to-send-the-escape-character-on-os-x-terminal/427#427 says that on Hungarian keyboard it is CTRL-5. On my ...
0
votes
1answer
863 views

Exiting Shell Script from if…else

I have a shell script which I want to exit based on the value of a variable ERROR_COUNT. I can either write if [ ${ERROR_COUNT} -gt 0 ] then echo "Exiting unsuccessfully"; exit 1; fi echo "...
3
votes
2answers
145 views

How can I get a confirmation before exiting screen?

How can I get a confirmation before I exit screen (when typing exit on the command-line). Is this possible?
3
votes
1answer
910 views

Really exit Awk script

Perl and Ruby exit actually exits: $ perl -e 'BEGIN {print 1; exit}; END {print 2}' 1 $ ruby -e 'BEGIN {print 1; exit}; END {print 2}' 1 Not so for Awk: $ awk 'BEGIN {print 1; exit}; END {print 2}'...
2
votes
2answers
901 views

bash + how to exit from secondary script and from the main script on both time

We run the script script1 from the script script_main script_main: #!/bin/bash /tmp/script1 echo $? sleep 2 echo script ended script1: #!/bin/bash exit 1 As is obvious, script1 exits with exit ...
6
votes
2answers
7k views

return value from eval

The bash manual states: eval [arg ...] The args are read and concatenated together into a single com- mand. This command is then read and executed by the shell, and ...
0
votes
1answer
277 views

How to resolve [1]+ Exit 1 error?

I want to run four different R codes on linux batch using the following command: nohup R CMD BATCH code_name.R& I could run 2 of the codes on background, but running the other two codes, I get ...
1
vote
3answers
567 views

Fail when one command fail in sub-command

I want to execute a command in a list of directories : gradle --build-cache. Additionnly the directory need to start with the string 'Project" and not ending with "Test". I succeed doing that with ...
1
vote
3answers
252 views

Difference between `exit;` and `exit $?;`

Is there any difference between these two commands: exec "$(dirname "$0")/suman-shell"; exit $?; and exec "$(dirname "$0")/suman-shell"; exit; is the $? redundant in the first case?
0
votes
1answer
1k views

How to exit out of a 'yes' loop [closed]

Using the command yes you can make a loop in the Linux terminal.  How do you exit out of said loop?  (I tried Ctrl+C but it didn't work).
1
vote
1answer
433 views

Closing terminal closes the application called through nohup

As far as I know, nohup signals ignores SIGHUP signal sent by the terminal to the application but the application can change that. I'm running Spotify through the command nohup spotify & and when ...
1
vote
2answers
2k views

Why do high exit codes on Linux shells (>= 256) not work as expected?

I discovered a strange behaviour (reproducible with zsh and bash on my system): $ # here everything is still normal $ bash -c 'exit 1';echo $? 1 $ bash -c 'exit 255';echo $? 255 $ zsh -c 'exit 255';...
1
vote
1answer
53 views

New prompt line not automatically put to command line upon exit code

When submitting jobs, I'm getting Exit codes returned, but I have to hit the return key for them to be printed to the log. 1. prompt_line/location sas query.sas & 2. [1] 66682 3. prompt_line/...
10
votes
7answers
2k views

Log exit code of command, similar to time command

using time sleep 1 yields: $ time sleep 1 real 0m1.005s user 0m0.001s sys 0m0.001s is there a command I can use to print the exit code of sleep or whatever command I want to run? ...
3
votes
1answer
534 views

Bash pipeline's exit status differs in script

The following bash pipeline returns 1: $ false | true $ echo $? 1 However it returns 0 when executed in an script: $ cat test.sh #!/usr/bin/env bash false | true echo $? $ bash test.sh 0 Can ...
1
vote
2answers
53 views

Bash: Help honing a custom function

I'm learning Bash, and I've written a basic function: wsgc () { # Wipe the global variable value for `getopts`. OPTIND=1; echo "git add -A"; while getopts m:p option; do ...
5
votes
2answers
716 views

Is there a simple test for anything printed on stderr in shell/Bash?

I'd like invoke a command inside a shell script for Continuous Integration purposes. Exit status 0 means succes, otherwise failure. I'm writing a wrapper script to run several commands and fail if any ...
0
votes
1answer
237 views

Exit codes in a startup script for different failures

I am running an Arch Linux installation and I have a systemd service that runs /etc/rc.local. In rc.local, I have several commands to perform things that I couldn't find a suitable solution for, like ...
4
votes
0answers
40 views

Behavior of set -e in function calls [duplicate]

I have an unusual problem with -e flag in a following bash script: #!/bin/bash -e foo() { return 1; } bar() { foo; bar; } bar || exit 1 Namely the script does not terminate, even though the foo ...
0
votes
2answers
153 views

Cannot exit bash script correctly

I have a made a script on bash. #!/bin/bash zen(){ mark=$(zenity --scale \ --text 'FREQUENCY' \ --value=$la \ --min-value=0\ --max-value=5000 \ --step=1) } la=500 echo "Script ...
1
vote
0answers
1k views

Bash error => “exit: code: numeric argument required” [closed]

I am getting this error: exit: code: numeric argument required on the line indicated below. git push production_dev HEAD:master exit_val=$? # error occurs here => exit: code: numeric argument ...
0
votes
1answer
617 views

Get exit code from preceding command before pipe [duplicate]

I have this: node ${SUMAN_RUNNABLE} | tee -a run.sh.log EXIT_CODE=$?; but it looks like the exit code is always 0 because tee is providing the code not the node executable. Is there a way to ...
5
votes
5answers
3k views

Getting “ensure” / “finally” functionality in a shell command (not script)?

I need to know whether a command has succeeded or failed, and unconditionally run some cleanup afterward. Neither of the normal options for executing sequential commands seem to be applicable here: ...
7
votes
3answers
794 views

How will bash evaluate following code

This question has two parts: (a) Understanding what the code snipped is doing (b) Understanding the difference between exit status and return status in context of bash. Here is the code snipped I ...
8
votes
4answers
3k views

Bash exit status used with PIPE

I am trying to understand how exit status is communicated when a pipe is used. Suppose I am using which to locate a non-existent program: which lss echo $? 1 Since which failed to locate lss I got ...
1
vote
1answer
84 views

exiting from script

I'm running aircrack-ng cmd inside a simple script #! /bin/bash clear echo "enter router mac \n" read mac echo "enter path to word list \n " read list echo "enter path to file contain handshake \...
0
votes
1answer
273 views

Trying to exit script with a status code but getting “unexpected end of file”

I'm using bash shell on Amazon Linux. I can't figure out why my script is dying with a syntax error. My script ends like so chmod 775 $TFILE2 output_file=$( create_test_results_file "$TFILE2" ) (...
-1
votes
2answers
477 views

Kill commands after a command

How to kill next commands when performing a conditional loop? My condition is as below and I want to exit the whole script if it shows echo "not found" so that whatever comes after this loop won't ...
1
vote
0answers
17 views

Keep a process alive after running it [duplicate]

If I were to forget to run nohup as described Keep SSH Sessions running after disconnection, would it be possible to keep a process alive after executing it. For example, I am running python program....
0
votes
1answer
729 views

How to create an alias to run a command and exit in bash?

Here is my alias. alias myAlias='myScript --option& && exit' I want to run the script myScript with option option in background and then exit from bash. I want to set it up as an alias ...
5
votes
2answers
4k views

How can I run two commands in parallel and terminate them if ONE of them terminates with exit code 0?

I have 2 commands which are to be run simultaneously. And I want the script to terminate if one of them either exits with code 0 or 1. How can I achieve this in Linux(Ubuntu) cmd1 & cmd2 & ...
4
votes
1answer
4k views

Difference between 'trap -⁠- EXIT' and 'trap - EXIT'

I've noticed that when Bash is called as sh, you cannot unset a trap using e.g., trap -- EXIT, but when it is called as bash you can. trap - EXIT seems to work regardless of how the shell was called. ...