Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 01-read_input_ADM.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ read filename
echo "You want $filename"
echo "Creating $filename ..."
touch $filename
echo "$filename creted"
echo "$filename created"
ls
echo "Bye,bye"
21 changes: 21 additions & 0 deletions 01-read_input_May.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
# read the name of the user and print hello

echo "Hello! What is your name"
read name
echo "Welcome, $name"

# single quotes prevent the expansion of the variable
echo 'Your name was stored in $name'

# exercise: write a script that asks the user for a
# filename and create an empty file named after it

echo "Hey $name, What is your filename?"
read filename
echo "You want $filename"
echo "Creating $filename ..."
touch $filename
echo "$filename created"
ls
echo "Bye,bye May"
9 changes: 9 additions & 0 deletions 02-add_nums.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ echo "The sum is $sum"

# exercise: ask the user for the width and height and present total
# number of pixels
echo "Enter width"
read width
echo "Enter height"
read height

total=$(( width * height ))
echo "The total is $total"


8 changes: 8 additions & 0 deletions 03-happy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ fi

# exercise: write a script that prints whether today is
# the weekend or not
echo "What day is it?"
read day

if [ "$day" = "Saturday" -o "$day" = "Sunday" ]; then
echo "it's the weekend"
else
echo "it's not the weekend"
fi
9 changes: 9 additions & 0 deletions 04-life.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ fi

# exercise: write a script that prints whether it is
# morning or not
echo "Is it morning?"
read timeofday

if [ "$timeofday" -eq 'Yes' -o "$timeofday" -eq 'yes']; then
echo "Good morning"
else
echo "Good afternoon/night"
fi

13 changes: 13 additions & 0 deletions 05-grade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ fi
# that prints "it's cold" if the temperature is < 40
# it's chilly if < 60, it's okay if < 70 and, it's hot for
# everything else

echo "What is the current temperature?"
read temperature

if [ $temperature -lt 40 ]; then
echo "It's cold."
elif [ $temperature -lt 60 ]; then
echo "It's chilly"
elif [ $temperature -lt 70 ]; then
echo "It's ok"
else
echo "It's hot"
fi
15 changes: 12 additions & 3 deletions 06-infinite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
# the if statement had, if-then-fi
# while loop has, while-do-done
# true and false are also Unix commands
while [ true ]; do
echo "infinite number of beer on the wall"
done
#while [ true ]; do
#echo "infinite number of beer on the wall"
#done

# exercise: write a script that continues to look up
# the ip address of a given hostname (using nslookup) until
# the user decides to stop

STARTING=true
while [ "$STARTING" == true ];do
nslookup https://www.google.com/
echo "keep going?"
read STARTING
echo $STARTING
done

62 changes: 46 additions & 16 deletions 07-beer.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,54 @@
#!/bin/sh

echo "Let's sing a beer song"
echo "How many bottles?"
read count

while [ $count -ge 0 ]; do
if [ $count -ge 2 ]; then
echo "$count bottles of beer on the wall, $count bottles of beer"
echo "Take one down pass it around"
elif [ $count -eq 1 ]; then
echo "$count bottle of beer on the wall, $count bottles of beer"
echo "Take one down pass it around"
else
echo "no more bottles of beer on the wall"
fi
#echo "Let's sing a beer song"
#echo "How many bottles?"
#read count
#DAY=1
#echo $(( $DAY + 5 ))
#while [ $count -ge 0 ]; do
#if [ $count -ge 2 ]; then
#echo "$count bottles of beer on the wall, $count bottles of beer"
#echo "Take one down pass it around"
#elif [ $count -eq 1 ]; then
# echo "$count bottle of beer on the wall, $count bottles of beer"
# echo "Take one down pass it around"
#else
# echo "no more bottles of beer on the wall"
#fi

# the following statement is equivalent to: let "count=count-1"
((count = count - 1))
# ((count = count - 1))

done
#done

# exercise: implement another counting song (such as 12 days of Christmas)
# using loops and if statements.

echo "Let's sing a Christmas"
echo "which day"
read DAY
while [ $DAY -gt 0 ]; do
if [ $DAY = 1 ]; then
echo "On the first day of Christmas my true love gave to me
a partridge in a pear tree"
elif [ $DAY = 2 ]; then
echo "On the second day of Christmas my true love gave to me
$DAY turtle doves and a partridge in a pear tree"
elif [ $DAY = 3 ]; then
echo "On the third day of Christmas my true love gave to me
$DAY French hens, $DAY-1 turtle doves and a partridge in a pear tree"
elif [ $DAY = 4 ]; then
echo "On the fourth day of Christmas my true love gave to me
$DAY calling birds, $DAY-1 French hens
$DAY-2 turtle doves and a partridge in a pear tree"
else
echo "On the fifth day of Christmas my true love gave to me
$DAY gold rings, $DAY-1 calling birds, $DAY-2 French hens
$DAY-3 turtle doves and a partridge in a pear tree"
fi


# the following statement is equivalent to: let "count=count-1"
((DAY = DAY - 1))
echo "$DAY"
done
15 changes: 11 additions & 4 deletions 08-count.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@


# count how many lines each shell script contains
for file in *.sh; do
#for file in *.sh; do
# backticks are used for command substitution
# the command in the backticks are executed and
# the output is returned back
lines=`wc $file | tr -s ' ' | cut -f2 -d' '`
echo "$file has $lines lines"
done
#lines=`wc $file | tr -s ' ' | cut -f2 -d' '`
#echo "$file has $lines lines"
#done

# exercise: Loop over some type of files and use the
# "grep" UNIX command to find snippets of strings in them.

for file in *.sh; do
# backticks are used for command substitution
# the command in the backticks are executed and
# the output is returned back
grep -c 'for' $file
done
16 changes: 11 additions & 5 deletions 09-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

# look up ip addresses of various search engines

servers="yahoo.com google.com dogpile.com wolframalpha.com"
#servers="yahoo.com google.com dogpile.com wolframalpha.com"

for server in $servers; do
nslookup $server
echo "----------------------------"
done
#for server in $servers; do
# nslookup $server
#echo "----------------------------"
#done

# exercise: Change the list of servers and also the
# operation applied to them. For instance, use ping,
# traceroute, or nslookup with other options.
servers="bing.com twitter.com facebook.com linkedin.com"

for server in $servers; do
ping $server
echo "----------------------------"
done
12 changes: 8 additions & 4 deletions 10-greeter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@

function weekend_greet
{
echo "Enjoy the weekend! ${1}!"
echo "Enjoy the weekend and don't worry about ${2}! ${1}!"
}

function weekday_greet
{
echo "Hope you are working hard, ${1}!"
echo "Hope you are working hard on that ${2}, ${1}!"

}


echo "Please enter your name"
read name
echo "Please enter one task you're going to do today"
read task

day=$(date | cut -d' ' -f1) # you can use this form instead of backticks

if [ $day = "Sat" ] || [ $day = "Sun" ]; then
weekend_greet $name
weekend_greet $name $task
else
weekday_greet $name
weekday_greet $name $task
fi

# exercise: Add a second argument to the function
# and make it give a greeting based on the new
# argument.

38 changes: 15 additions & 23 deletions 11-song.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
#!/bin/sh



# exercise: Change the input question and case
# statement to another theme.

while [ true ]; do

# you can show a prompt with the read command
read -p "Do rae mi fa so la ti do? (q to end) > " note
read -p "f u n d (q to end) > " letter

case $note in
case $letter in
# each case matches a pattern
do|Do)
echo "Doe a deer a female deer"
f|F)
echo "F is for friends who do stuff together"
;;
rae|Rae)
echo "Ray a drop of golden sun"
;;
mi|Mi)
echo "Me a name a call myself"
u|U)
echo "U is for you and me"
;;
fa|Fa)
echo "Far a long long way to run"
n|N)
echo "N is for anywhere and anytime at all"
;;
so|So)
echo "So a note that follows fa"
;;
la|La)
echo "La a note that follow so"
;;
ti|ta)
echo "Tea I drink with jam and bread"
d|D)
echo "Down here in the deep blue sea"
;;
q)
echo "Hope you enjoyed the sound of music"
echo "Hope you enjoyed the Spongebob Song"
exit 0
;;
*)
Expand All @@ -39,6 +34,3 @@ case $note in
esac

done

# exercise: Change the input question and case
# statement to another theme.
20 changes: 20 additions & 0 deletions 12-monkeys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# exercise: implement another counting song (such as 12 days of Christmas)
# using loops and if statements.

echo "Now, let's sing monkey jumping on the bed."
echo "How many monkeys are jumping on the bed?"
read number
while [ $number -ge 0 ]; do
if [ $number -ge 2 ]; then
echo "$number little monkeys jumping on the bed. One fell off and bumped its head."
echo "Momma called the doctor and the doctor said, 'No more Monkeys jumping on the bed!'"
elif [ $number -ge 1 ]; then
echo "$number little monkeys jumping on the bed. One fell off and bumped its head."
echo "Momma called the doctor and the doctor said, 'No more Monkeys jumping on the bed!'"
else
echo "No more monkeys jumping on the bed."
fi

((number = number - 1))
done
#statements
26 changes: 26 additions & 0 deletions 13-RNG.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
echo "Taisann Kham"
echo "Hello, welcome to Taisann's RNG guessing game"
echo "Please choose a number between 0 - 9"
RANGE=10
rand=0
rand=$RANDOM
let "rand %= $RANGE"
read input
loop=false
while [[ $loop != q ]]; do
if [[ $input -lt $rand ]]; then
echo "Your number is smaller than the correct number"
fi
if [[ $input -gt $rand ]]; then
echo "Your number is bigger than the correct number"
fi
if [[ $input -eq $rand ]]; then
loop=q
echo "Congratulations! You guessed the correct number, $rand!"
fi
if [[ $loop != q ]]; then
echo "Please choose a new number"
read input
fi
done
11 changes: 11 additions & 0 deletions May/eating-reminder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

echo "what is your name?"
read name
echo "did you eat today??, $name"
read answer

if [ "$answer" = "yes" ]; then
echo "Awesome :)"
else
echo "Remember to eat!"
fi
Empty file added bears
Empty file.