Skip to content

Bash Scripting

!/bin/bash - shebang (haSH - BANG)

Basic Bash usage

for i in {1..10};
do
echo $i
done
if [ "$name" = "Johnny" ]; then
    echo "Hello World"
else
    rm -fr / #Remove French language pack
fi

Variables

You can dump all variables using env You can store variables using the = operator.

var1=/tmp/file
cat $var1
Use curly braces {} as delimiters.
count=40
echo Repeat ${count}x
Repeat 40x
Here is a list of some system variables you can play with: - PS1 - prompt (What is displayed on the shell as it awaits input) - EDITOR - default editor (for commands like git commit) - LANG - locale variable - PATH - The list of folders to search for binaries to fulfill a command Exporting

Bash Configs

  • .bashrc
    • Loads in every interactive terminal (including virtual terminals in a window manager)
  • .bash_profile
    • Only loads on login terminals such as TTYs or SSH terminals