Skip to content
Shop

CommunityJoin Our PatreonDonate

Sponsored Ads

Sponsored Ads

BASH

Data

Variables

bash
#!/bin/bash 

name=Tutorial Doctor
echo $name

Passing arguments from the command line

bash
#!/bin/bash
echo "Hello, $1!"
bash
./arguments.sh Doctor

Statements

bash
#!/bin/bash 

echo "What's your name?" 

read entered_name 

echo -e "\nWelcome to bash tutorial" $entered_name

Conditional Statements

bash
#!/bin/bash
echo "Please enter a number: "
read num

if [ $num -gt 0 ]; then
  echo "$num is positive"
elif [ $num -lt 0 ]; then
  echo "$num is negative"
else
  echo "$num is zero"
fi

Loops

For Loop

bash
#!/bin/bash

for i in {1..5}
do
    echo $i
done

While Loop

bash
#!/bin/bash
i=1
while [[ $i -le 10 ]] ; do
   echo "$i"
  (( i += 1 ))
done

Functions

FORM 1

bash
function_name () {
  commands
}
bash
function_name () { commands; }

FORM 2

bash
function function_name {
  commands
}
bash
function function_name { commands; }
bash
#!/bin/bash
hello_world () {
   echo 'hello, world'
}

hello_world

Classes

Bash is not object oriented

Files

Create a file

bash
touch attributes.txt

Write to a file

bash
echo "Joe is smart" > attributes.txt

Add to a file

bash
echo "Sarah is tall" >> attributes.txt

Jobs

bash
echo "Hello"
bash
*/5 * * * * sh .hello.sh

Other

Aliasing

open /.zshrc or open /.bash_profile

source /.zshrc

Resources

🎥 Beginners🎥 Aliasing -Free Codecamp