functions.sh: Add more useful explainations
This commit is contained in:
parent
f5acfc3e1c
commit
170da4f6d6
87
functions.sh
87
functions.sh
@ -1,16 +1,81 @@
|
||||
#!/bin/bash
|
||||
|
||||
fuck(){
|
||||
echo "fuck you"
|
||||
echo ""
|
||||
######################################################
|
||||
## filename: functions.sh
|
||||
## Description: Learn how to use functions in bash
|
||||
## Notes: Fucntions have to be called or 'run' to use them
|
||||
## Run a function by typing it's name
|
||||
## variable names such as 'user_input' can be named anything
|
||||
## you cannot run a function before you create/defne it
|
||||
#####################################################
|
||||
|
||||
slap(){
|
||||
|
||||
echo -n "who wants to get slapped: " # use echo command without automatic newline
|
||||
read user_input # "read": reads what user typed and store in variable called 'user_input'
|
||||
|
||||
# use double brackets to make code run more reliably in bash (does not work in other shells)
|
||||
if [[ $user_input = "me" ]];then
|
||||
echo "you gets a slap"
|
||||
elif [[ $user_input = "you" ]];then
|
||||
echo "you still get slapped"
|
||||
fi
|
||||
}
|
||||
|
||||
ipp(){
|
||||
echo Public IP
|
||||
curl -s icanhazip.com
|
||||
echo
|
||||
echo Local IP
|
||||
/sbin/ifconfig enp3s0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
|
||||
block_tutorial(){
|
||||
# Show how to test if something is a device or not
|
||||
|
||||
echo -n "enter a block device name: " # ask and print the question
|
||||
read user_input # read the users response and puts it into the variable "user_input"
|
||||
|
||||
if [[ -b $user_input ]];then # the user enters a device name and -b tests if it is a block device
|
||||
echo "This is a block device"
|
||||
elif [[ ! -b $user_input ]];then # "!" specifically checks if user_input is NOT a block device
|
||||
echo "This is not a block device"
|
||||
fi
|
||||
}
|
||||
fuck
|
||||
ipp
|
||||
|
||||
file_tutorial(){
|
||||
# Show how to test if something is a file or not
|
||||
|
||||
echo -n "enter file name: " #asks for a filename to test
|
||||
read user_input # reads the users response and puts it into the variable "user_input"
|
||||
|
||||
if [[ -f $user_input ]];then
|
||||
echo "This is a file"
|
||||
elif [[ ! -f $user_input ]];then
|
||||
echo "This is not a file"
|
||||
fi
|
||||
}
|
||||
|
||||
folder_tutorial(){
|
||||
#Show if something is a folder or not
|
||||
|
||||
echo -n "enter folder path: " #asks for folder path
|
||||
read user_input # reads the users response and puts it into the variable "user_input"
|
||||
|
||||
if [[ -d $user_input ]];then
|
||||
echo "this is a folder"
|
||||
elif [[ ! -f $user_input ]];then
|
||||
echo "this is not a folder"
|
||||
fi
|
||||
}
|
||||
|
||||
empty_variable(){
|
||||
# Show if a variable it empty or not
|
||||
|
||||
echo -n "Enter some text: " #asks user to enter random text
|
||||
read some_text # read what user typed and store it into variable called "some_text"
|
||||
|
||||
if [[ -z $some_text ]];then
|
||||
echo "There is nothing stored in the varialbe 'some_text'"
|
||||
elif [[ ! -z $some_text ]];then
|
||||
echo "The user has entered in some text!"
|
||||
fi
|
||||
}
|
||||
# run functions created above or comment them to stop them from running
|
||||
slap
|
||||
block_tutorial
|
||||
file_tutorial
|
||||
folder_tutorial
|
||||
empty_variable
|
Loading…
x
Reference in New Issue
Block a user