BASH
Data
Variables
bash
#!/bin/bash
name=Tutorial Doctor
echo $namePassing arguments from the command line
bash
#!/bin/bash
echo "Hello, $1!"bash
./arguments.sh DoctorStatements
bash
#!/bin/bash
echo "What's your name?"
read entered_name
echo -e "\nWelcome to bash tutorial" $entered_nameConditional 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"
fiLoops
For Loop
bash
#!/bin/bash
for i in {1..5}
do
echo $i
doneWhile Loop
bash
#!/bin/bash
i=1
while [[ $i -le 10 ]] ; do
echo "$i"
(( i += 1 ))
doneFunctions
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_worldClasses
Bash is not object oriented
Files
Create a file
bash
touch attributes.txtWrite to a file
bash
echo "Joe is smart" > attributes.txtAdd to a file
bash
echo "Sarah is tall" >> attributes.txtJobs
bash
echo "Hello"bash
*/5 * * * * sh .hello.shOther
Aliasing
open /.zshrc or open /.bash_profile
source /.zshrc


