Questions tagged [exit]
The exit tag has no usage guidance.
205
questions
0
votes
1
answer
32
views
exit ssh when prompt for new password
I am looking for a way to exit ssh when password expires.
I have a script that is checking few things on all VMs in infrastructure.
Unfortunately there are few VMs with password auth method.
5
votes
1
answer
185
views
Why does bash print exit even when it does not exit - is this a bug?
exit with zero or one numeric argument like exit or exit 42 print "exit" and exit the shell.
exit with an invalid argument like exit hello prints an error message, prints "exit" ...
0
votes
2
answers
164
views
How to make a script fail when there is an error in here string?
I have a script similar to this:
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
while read -r l; do
echo "${l}"
done <<< "$(cat input.txt)"
echo Success
The command cat ...
0
votes
1
answer
182
views
How to run dmesg -w in the background
So I have a command that crashes the computer, and I wanted to see the output of dmesg to figure out the reason.
I saw that there is an -w option that allows dmesg to follow the process, but the ...
0
votes
2
answers
2k
views
How do you continue execution after using trap EXIT in bash?
Environment: GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin20)
I'm attempting to trap the exit from another function but then continue executing the program. In an object oriented language ...
0
votes
0
answers
268
views
EXIT trap is ignored on Ctrl-C when PID == 1
a.sh:
trap 'echo cleanup' EXIT
sleep 3
To reproduce, press Ctrl-C before the script finishes:
$ docker run --rm -itv $PWD:/app -w /app alpine:3.14 sh a.sh
^Ccleanup
$ docker run --rm -itv $PWD:/app -...
1
vote
1
answer
221
views
AppImage doesn't run when using "; exit" after the command
I downloaded the AppImage of Syncplay and put it in $HOME/Applications and created an alias in zsh to run it from terminal and then exit. In ~/.zshrc I have,
$ grep syncplay ~/.zshrc
alias syncplay=&...
1
vote
2
answers
58
views
Interpretation of Open Group Base Specification's description of exit()
In the exit() function description of the Open Group Base Specifications (various issues), we read:
The exit() function shall first call all functions registered by
atexit(), in the reverse order of ...
-2
votes
2
answers
3k
views
Use exit, but do not close terminal, in bash script
I have created a shell function to comfortably use desktop search tool baloosearch. I created it as a function for a reason.
Now, in this functions I need to use exit command to quit loops, ifs or ...
0
votes
1
answer
271
views
how to exit in bash script from ProFTPD via netcat after some copy operations
I am connecting to a proftpd server via netcat
nc 10.10.239.150 21
Then I am doing some copy operations like
"The mod_copy module implements SITE CPFR and SITE CPTO commands"
After "...
0
votes
3
answers
330
views
How do I automatically close the process left behind by a misbehaving application after it exits?
There are applications that do not exit cleanly leaving behind their process. One example I've found is Foxit Reader. Of course, the ideal would be to report a bug and have the application fixed, but ...
1
vote
0
answers
332
views
Is it possible to exit `podman run -t` if standard input is redirected?
When I run
podman run -t "" alpine:3 sh
Everything works and is kosher, and I can exit by typing exit, or CONTROL+P, CONTROL+Q. However, if I run
podman run -t "" alpine:3 sh <&...
0
votes
2
answers
2k
views
Is the sigspec for 0 EXIT or SIGEXIT or exit?
I need to write a trap which tracks when a process exits (amongst other things) and removes a temporary file. I'd prefer to use the sigspec instead of number for better code readability, the relevant ...
0
votes
1
answer
135
views
Can't stop script l loop with exit command
I've got a debug function in my script (that runs via nemo.action) that uses zenith popup to ask if the user want to stop or continue when an error occurs.
However, when this happens inside a loop, ...
3
votes
1
answer
158
views
Bash Shell "onecmd" Option Usage Purpose [duplicate]
I read on man page, but I don't understand the purpose of bash's onecmd option. If I use the set -o onecmd command, the shell immediately exits. My expectation is for it to wait for me to enter one ...
3
votes
2
answers
580
views
How to propagate an error code outside a terminal?
From inside a bash script I try to retrieve the error code of a program launched in a new terminal window. It can be reduced to this:
#!/bin/bash
urxvt -e bash -c "exit 4"
echo $?
output: 0
I would ...
2
votes
1
answer
259
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 ...
7
votes
1
answer
996
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 ...
6
votes
1
answer
2k
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
1
answer
2k
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
1
answer
381
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
1
answer
1k
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 ...
7
votes
1
answer
1k
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
1
answer
370
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 /...
36
votes
3
answers
8k
views
In Bash, 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
2
answers
2k
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 ...
5
votes
1
answer
4k
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 ...
5
votes
2
answers
2k
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
0
answers
44
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
5
answers
7k
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 "$...
7
votes
3
answers
27k
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
2
answers
1k
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
1
answer
2k
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
1
answer
2k
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 ...
8
votes
1
answer
3k
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"
...
12
votes
2
answers
6k
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
4
answers
2k
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 ...
1
vote
1
answer
362
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 ...
13
votes
3
answers
18k
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
...
2
votes
2
answers
872
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
0
answers
69
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 ...
1
vote
1
answer
4k
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 ...
1
vote
1
answer
6k
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
3
answers
1k
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?
5
votes
1
answer
4k
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}'...
7
votes
2
answers
6k
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 ...
11
votes
2
answers
29k
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
...
1
vote
1
answer
1k
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
3
answers
2k
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 ...
3
votes
3
answers
6k
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?