0

Say I want to touch mickymouse in /tmp

I can do

cd /tmp ; touch mickymouse

or I can do

cd /tmp && touch mickymouse

I'm not clear what the subtle (or less subtle) differences are between the two statements.

Would appreciate comments on the difference between the two.

Thanks.

4

2 に答える 2

6

; terminates the statement whereas && is the logical AND.

cd /tmp ; touch mickymouse

In the above, even if cd /tmp failed, touch mickymouse will still be executed.

In the second one,

cd /tmp && touch mickymouse

Do touch mickymouse only if cd /tmp succeeded

于 2013-01-30T18:43:49.200 に答える
1

See that && is special operation where the RHS of && is always executed only when LHS of && is true.

or only when /tmp is available, you will be able to touch mickymouse.

Whereas in the earlier case, it just returns an error as /tmp not available.

Or you can just do effectively as

touch /tmp/mickymouse
于 2013-01-30T18:44:30.013 に答える