Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate a crashing bash script

Tags:

bash

exception

I'm trying to test a bash script that restarts it's child process when the child process has crashed.
How do I make a bash script crash on purpose?

(I'm trying to test the script that restarts the process)

like image 269
Bart Gloudemans Avatar asked May 01 '14 22:05

Bart Gloudemans


People also ask

What does [- Z $1 mean in bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.

What is $@ bash script?

bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.

What is bash trap command?

A built-in bash command that is used to execute a command when the shell receives any signal is called `trap`. When any event occurs then bash sends the notification by any signal. Many signals are available in bash. The most common signal of bash is SIGINT (Signal Interrupt).


1 Answers

Do you mean something like this?

# this simulates a script returning exit code of 1
sh -c 'exit 1'
like image 64
voho Avatar answered Oct 23 '22 02:10

voho