Bash (Unix shell): Difference between revisions
| (One intermediate revision 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 145: | Line 145: | ||
===alias=== | ===alias=== | ||
You can add aliases to your <code>.bashrc</code> to make commmon commands shorter. | You can add aliases to your <code>.bashrc</code> to make commmon commands shorter. | ||
< | <syntaxhighlight lang="bash"> | ||
alias kc=kubectl | alias kc=kubectl | ||
alias tb="tensorboard --logdir" | alias tb="tensorboard --logdir" | ||
</ | </syntaxhighlight> | ||
==dirname== | ==dirname== | ||