Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash command and return status

Tags:

bash

pkill return status > 0 if error ( for example if not found process ). How to return 0 status independing result of pkill ?

like image 708
Bdfy Avatar asked Mar 21 '11 11:03

Bdfy


People also ask

What is the return command in bash?

The return Command. return stops the execution of a Bash function. If we supply an integer argument to return, it returns that argument to the function caller as the exit status. Otherwise, it returns the exit status of the last command executed before return to the function caller.

How do I check my bash return?

To check the exit code we can simply print the $? special variable in bash. This variable will print the exit code of the last run command. $ echo $?

What is $? == 0 in shell script?

$? is the exit status of the most recently-executed command; by convention, 0 means success and anything else indicates failure. That line is testing whether the grep command succeeded. The grep manpage states: The exit status is 0 if selected lines are found, and 1 if not found.

What is exit $?

After a script terminates, a $? from the command-line gives the exit status of the script, that is, the last command executed in the script, which is, by convention, 0 on success or an integer in the range 1 - 255 on error. Example 6-1. exit / exit status.


1 Answers

Either just don't test for the result, or do:

pkill whatever || true
like image 56
Erik Avatar answered Nov 14 '22 00:11

Erik