Wednesday, 15 April 2015

linux - && vs & with the test command in bash -



linux - && vs & with the test command in bash -

gndlp@ubuntu:~$ test -x examples.desktop && echo $? gndlp@ubuntu:~$ test -x examples.desktop & echo $? [1] 2992 0

why bash acting way in situation? test command not finishing , echo command isn't processed?

the meaning of && , & intrinsically different.

what && in bash? in bash—and many other programming languages—&& means “and”. , in command execution context this, means items left right of && should run in sequence in case. what & in bash? , single & means preceding commands—to immediate left of &—should run in background.

so looking @ example:

gndlp@ubuntu:~$ test -x examples.desktop && echo $? gndlp@ubuntu:~$ test -x examples.desktop & echo $? [1] 2992 0

the first command—as structured—actually not homecoming anything. sec command returns [1] 2992 in 2992 refers process id (pid) running in background , 0 output of first command.

since sec command running test -x examples.desktop in background happens quite process id spawned , gone pretty immediately.

linux bash

No comments:

Post a Comment