Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invoking a bash script by itself

I need to invoke a bash script by itself with a different set of arguments that would make it run as a background process, so I am using something like:

if [[ $a == $b  ]]
then
  $0 -v &> /dev/null
fi

The issue is that though I am invoking the same script as a background process using '&' as suffix and redirecting all outputs to /dev/null, the terminal that I invoke the script is not released, I am assuming that is because of the script which initially was invoked has a process which is running as a foreground process, so the query is, how to call a bash script by itself such that when it calls itself the process which is responsible for running the script for the first time is killed and the console released and the second call to itself runs as a background process?

like image 234
Nohsib Avatar asked Dec 03 '22 08:12

Nohsib


1 Answers

You're not running it as a background process using &. &> is a completely separate token that redirects stdout and stderr at the same time. If you wanted to put that command in the background it would be $0 -v &>/dev/null &.

like image 70
hobbs Avatar answered Dec 11 '22 17:12

hobbs