'&&' vs. '&' with the 'test' command in Bash

后端 未结 3 753
面向向阳花
面向向阳花 2020-11-29 06:40

Consider:

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

W

3条回答
  •  天命终不由人
    2020-11-29 06:56

    & executes a command in the background, and will return 0 regardless of its status.

    From the man page:

    If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Commands separated by a ; are executed sequentially; the shell waits for each command to terminate in turn. The return status is the exit status of the last command executed.

提交回复
热议问题