bash:if...then...else
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
bash:if...then...else [2021/05/28 08:41] – peter | bash:if...then...else [2021/05/28 08:42] (current) – peter | ||
---|---|---|---|
Line 102: | Line 102: | ||
===== AND ===== | ===== AND ===== | ||
+ | Use **&& | ||
+ | |||
+ | <code bash> | ||
#!/bin/bash | #!/bin/bash | ||
Line 111: | Line 114: | ||
else | else | ||
echo "Odd Number" | echo "Odd Number" | ||
+ | fi | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== OR ===== | ||
+ | |||
+ | Use **||**. | ||
+ | |||
+ | |||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | |||
+ | echo -n "Enter any number:" | ||
+ | read n | ||
+ | |||
+ | if [[ ( $n -eq 15 || $n -eq 45 ) ]] | ||
+ | then | ||
+ | echo "You won" | ||
+ | else | ||
+ | echo "You lost!" | ||
fi | fi | ||
</ | </ |
bash/if...then...else.1622191287.txt.gz · Last modified: 2021/05/28 08:41 by peter