Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does 1>/dev/null 2>&1 & pid1=$! mean?

I am learning how to run multiple processes in parallel

  ./script1.sh param1 1>/dev/null 2>&1 &
  pid1=$!
  ./script1.sh param2 1>/dev/null 2>&1 &
  pid2=$!

I am not sure what is happening here:

   1>/dev/null 2>&1
   pid1=$!
like image 246
Angelina Avatar asked Nov 13 '13 20:11

Angelina


1 Answers

Redirect standard output (file handle 1) to /dev/null

1>/dev/null

Redirect standard error (file handle 2) to standard output

2>&1

Assign the PID of the most recent background command to variable pid1 (more in bash man page, special parameters)

pid1=$!

The result is that both standard output and standard error are redirected to /dev/null

More examples can be found here: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html

Normally three files are opened to a program: standard input, standard output and standard error. You can read more about standard streams or redirection at wikipedia.

The following part of the script:

./script1.sh param1 1>/dev/null 2>&1 &
pid1=$!

Translated to plain English:

From current directory ./ run a program script1.sh with parameter param1 and redirect standard output to /dev/null 1>/dev/null and redirect standard error to standard output 2>&1and let the program run in the background &. Assign the PID of the program that was just started in the background to pid1 pid1=$!.

like image 176
some Avatar answered Nov 10 '22 14:11

some