ampersand at beginning of a line in csh

2019-05-09 22:15发布

问题:

What does an ampersand at the beginning of a line do in csh? It seems to be ignored (with no error message), but why?

回答1:

Found something interesting:

The semicolon (;) character separates successive commands on a single command line. For example,

% <command1> ; <command2>

executes <command1>, and when it finishes, <command2> gets executed.

The ampersand character (&) is similar to the semicolon (;) but does not wait for <command1> to finish.

Maybe it's treating it like an empty command?



回答2:

The best way to answer will be example. Taking idea of JoelFAn ahaed:

EXAMPLE 1

user$ date ; sleep 5s ; date

Thu Apr 5 10:46:45 IST 2012

Thu Apr 5 10:46:50 IST 2012

EXAMPLE 2

user$ date & sleep 5s & date

[1] 18371

[2] 18372

Thu Apr 5 10:47:09 IST 2012

Thu Apr 5 10:47:09 IST 2012

[1] - Done date

EXAMPLE3

user$ bg

[2] sleep 5s &

The examples are self explanatory.

Thanks



回答3:

I can't find anything in csh docs about it. However, I know in make it suppresses any output from the command (but still runs it). Perhaps that's what it is doing.