Questions tagged [exit]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
1answer
31 views

Question about a process lifecycle

I've managed to question myself about the wait(2) and _exit(2) system calls in a process lifecycle. My question about the wait(2) system call is... does the parent process issue it to the kernel? Or ...
3
votes
0answers
42 views

How do I exit less when reading from stdin when it is called with a single minus argument: “less -”

Is there a proper way to exit less - without having to kill the process? I accidently created a file called - (minus) and tried to view it with: less - Less than follows stdin and I did not find ...
4
votes
1answer
160 views

In bash, how can I retrieve the exit code of a subshell when using local

This question is close to others - Can I get the exit code from a sub shell launched with $(command)? However there are no solutions I've found that allows me to get an exit code from a sub shell ...
0
votes
1answer
53 views

How to follow-up a command with Ctrl + D (EOF)

I would like to run a few commands and give an explicit Ctrl+D, just like, say: ls;pwd;^D Unfortunately, the above doesn't work. I've also tried \04 and 0x4 in place of ^D above as mentioned here. ...
1
vote
1answer
80 views

Perform special action on bash timeout

This question is related only to bash, no ssh or any other tool. I would like to detect a bash timeout, and only a timeout: I am NOT interested in any other exit conditions (exit, EOF, ^D, or ...
1
vote
1answer
99 views

nohup exiting with error 125

nohup exits with Error 125 when trying to start a Python script in the background, yet when using wildcards, pointing to the very same file, nohup works. root@rpi_2:/home/pi/shortcuts# nohup -c ...
6
votes
1answer
294 views

Running script line by line automatically yet being asked before each line from second line onwards

I work on a script of about 20 lines which I find myself testing time and again by copy-pasting and executing line by line. Instead of copying-pasting each line and hitting Enter to execute, I would ...
0
votes
1answer
54 views

Confusion about how a systemd service is restarted

I am still confused about systemd services being active vs the process still running vs not running etc. Let's say I have the following basic shell script called my_script.sh : #!/bin/sh touch /...
28
votes
3answers
5k views

How can I detect if I'm in a subshell?

I'm trying to write a function to replace the functionality of the exit builtin to prevent myself from exiting the terminal. I have attempted to use the SHLVL environment variable but it doesn't seem ...
1
vote
2answers
328 views

Exit shell with running process in foreground

I have a process running the foreground. I am wondering if it's possible to exit Bash, without (of course) killing the foreground process and exiting as usual, and without killing the terminal ...
0
votes
1answer
643 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 ...
3
votes
2answers
654 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
30 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
4k 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
3answers
2k 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
143 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
800 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
116 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
1k 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" ...
11
votes
2answers
3k 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
758 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
39 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
125 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 ...
7
votes
3answers
4k 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
66 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
52 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
1answer
810 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
2k 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 "...
2
votes
2answers
356 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
2k 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}'...
5
votes
2answers
3k 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 ...
7
votes
2answers
13k 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
468 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
965 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 ...
2
votes
3answers
735 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?
1
vote
1answer
2k 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).
2
votes
1answer
578 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 ...
3
votes
2answers
3k 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';...
0
votes
1answer
67 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
3k 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? ...
4
votes
1answer
850 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
55 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
2k 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
332 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
42 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
244 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 ...
0
votes
1answer
1k 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 ...
6
votes
5answers
5k 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
848 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 ...
10
votes
4answers
4k 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 ...