Quote:
Originally Posted by BudiKusasi
will do output, for example:
/usr/local/bin:/usr/bin:/bin:/opt/bin:
have a nice day!
as it is analogous to windows:
cmd /c "echo %path% & echo have a nice day!"
|
It depends on what you want as output, and whether you want the second part to depend on the first.
To get the output based on your example, something like one of these would work...
Code:
echo ${PATH} && echo "Have a nice day!"
echo ${PATH}; echo "Have a nice day!"
The
&& is a conditional
and operator, often called a short-circuit operator, and means that if the part on the left succeeds then do the part on the right, so execution of the second is conditional, it depends on the success of the first (see below).
The
; denotes the end of a command and allows you to put multiple commands on a single line, without dependence on each other.
Conditional expressions are more useful for constructs other than simply echoing output (which presumably always succeeds). You might try something like this:
Code:
((1<0)) && echo "Have a rainy day"
((1>0)) && echo "Have a nice day"
If the math condition in ((..)) is true, then the string will be echoed, otherwise not.