Bash (Unix shell): Difference between revisions
| (3 intermediate revisions by the same user not shown) | |||
| Line 20: | Line 20: | ||
[https://linuxize.com/post/bash-if-else-statement/ https://linuxize.com/post/bash-if-else-statement/] | [https://linuxize.com/post/bash-if-else-statement/ https://linuxize.com/post/bash-if-else-statement/] | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
if [[ $VAR -gt 10 ]] then | if [[ $VAR -gt 10 ]]; then | ||
echo "The variable is greater than 10." | echo "The variable is greater than 10." | ||
elif [[ $VAR -eq 10 ]] then | elif [[ $VAR -eq 10 ]]; then | ||
echo "The variable is equal to 10." | echo "The variable is equal to 10." | ||
else | else | ||
| Line 44: | Line 44: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
# Check if user is root (https://stackoverflow.com/questions/18215973/how-to-check-if-running-as-root-in-a-bash-script) | # Check if user is root (https://stackoverflow.com/questions/18215973/how-to-check-if-running-as-root-in-a-bash-script) | ||
if [ "$EUID" -ne 0 ] | if [ "$EUID" -ne 0 ]; then | ||
echo "Please run as root" | |||
exit | exit | ||
fi | fi | ||
| Line 66: | Line 66: | ||
/media/veracrypt7 | /media/veracrypt7 | ||
/media/veracrypt8 | /media/veracrypt8 | ||
) | ) | ||
# Add to the array | |||
DRIVES+=(/media/veracrypt9) | |||
for i in "${DRIVES[@]}" | for i in "${DRIVES[@]}" | ||
| Line 140: | Line 141: | ||
<code>--</code> explicitly ends non-positional arguments for many commands | <code>--</code> explicitly ends non-positional arguments for many commands | ||
===alias=== | |||
You can add aliases to your <code>.bashrc</code> to make commmon commands shorter. | |||
<syntaxhighlight lang="bash"> | |||
alias kc=kubectl | |||
alias tb="tensorboard --logdir" | |||
</syntaxhighlight> | |||
==dirname== | ==dirname== | ||