Skip to main content

Questions tagged [error-handling]

Use this tag for questions on how to handle errors generated in shell scripts.

2 votes
1 answer
138 views

Bash exception handling with a stack trace and cleanup code - how to implement?

When using the set -e flag in Bash, then it's difficult to get user-friendly error messages (a stack trace) and it's difficult to add cleanup code that executes before your script exits with an error ...
user3207874's user avatar
0 votes
1 answer
82 views

bash function returns 0 when it seemingly should return 1 or 2

bash 4.4.20(1)-release. (No portability required.) This function works great when I pass it a valid DB name: Get_ValidDB() { local pDB=$1 [ -z $pDB ] && { printf '||Requires a DB name.'...
RonJohn's user avatar
  • 1,473
1 vote
0 answers
73 views

rename "Duplicate specification" for option error

The other day something started going wrong with the perl rename terminal command that was pre-installed on my system; which is Ubuntu 22.04.5 LTS. When I try to use any version of the rename command ...
Danae Stephens's user avatar
0 votes
0 answers
45 views

Apache2 PHP error_log() doesn't work when called in some PHP code

On my Linux Ubuntu system I run apache2 web server in the context of a PHP based web application. phpinfo() reports the following error_log /opt/unetlab/data/Logs/php_errors.txt I.e. error_log() is ...
CarloC's user avatar
  • 385
0 votes
0 answers
29 views

Why is set -e also ignored for functions called via command substitution [duplicate]

I've seen questions about this topic, but they talk about constructs like if or ||. I don't understand why the same behavior seem to happen for substitution ($())? $ my_function() { echo "the ...
Jakub Bochenski's user avatar
0 votes
1 answer
155 views

How can I set a bash script to wait for user input (not exit) on error?

I know that set -e tells bash to exit the script on error. The problem is that I have to address the error, then delete all previous steps from the script while maintaining any variables before ...
user2013318's user avatar
1 vote
1 answer
98 views

Help figuring out how to handle errors in "mongodump" script

I have a simple bash script that's supposed to create a dump file from a database docker exec -i container sh -c "mongodump --archive" > \ ~/dumps/db-$(date + "%d%m%Y").dump ...
Ambre's user avatar
  • 111
1 vote
0 answers
89 views

What's the logic in exiting early on failure in blocks and subshells in Bash? [duplicate]

In Bash blocks {} and subshells () the exit early doesn't work if there is an OR condition following it. Take for example set -e { echo a; false; echo b; } || echo c prints a b and set -e { echo a; ...
QuickishFM's user avatar
0 votes
2 answers
588 views

How to execute command if previous command fails with return code 0

I have a script which logs in to a server. Regardless of the success (i.e. whether the password is valid or not) the script will exit with return code 0, and the text: Error login failed. I'd like it ...
Nickotine's user avatar
  • 554
0 votes
2 answers
301 views

tar: ./.tar.gz: file changed as we read it | "Flagged" files are unrelated to the file tar is supposed to operate on

I am trying to use tar to recursively compress all files with the .lammpstrj extension within the directory tree starting at the directory whose path is stored in the variable home. home contains the ...
Felipe Evaristo's user avatar
1 vote
0 answers
87 views

bash: is it possible to make `errexit` work inside conditionals?

Consider the following script: #!/bin/bash set -o errexit -o xtrace qux() { false echo QUX } quux() { qux ||: echo QUUX } quux Running this script produces: + quux ...
Azat Khabibulin's user avatar
1 vote
1 answer
439 views

Bash parameter substitution with multi line error message

I'm using parameter substitution with an error message, such as ${var1:?'some message'}. I've incorporated a multi-line error message. Presently, it only functions properly when enclosed within single ...
programmer Erfan's user avatar
0 votes
1 answer
160 views

Some GTk3 applications aborting with BadAccess when DISPLAY=:0 but not DISPLAY=hnam.local:0 or even DISPLAY=unix:0

I've had some issues with my XQuartz environment not starting due to a bit of a freak reason that was a rather hard to figure out. It's (mostly) working again but I must have caused another regression ...
RJVB's user avatar
  • 274
3 votes
1 answer
288 views

How to code defensively in Bash for unhandled runtime errors within logical expressions?

I just encountered an error where a function was missing in my script. I already trap and raise these exceptions to stop the script early, but I noticed that did not occur. Investigating this further, ...
Zhro's user avatar
  • 2,841
-5 votes
1 answer
86 views

virtual machine stuck [closed]

My virtual machine stuck on this and just keep downloadin for hours please solve
muhammad wajahat ali khan's user avatar

15 30 50 per page
1
2 3 4 5
23