Scripting CBIS 4225. BASH Scripting Step 1 – Create the bash file. Usually a good idea to end it...
-
Upload
rolf-walters -
Category
Documents
-
view
214 -
download
0
Transcript of Scripting CBIS 4225. BASH Scripting Step 1 – Create the bash file. Usually a good idea to end it...
Scripting
CBIS 4225
BASH Scripting
• Step 1 – Create the bash file. Usually a good idea to end it in .shfile1.sh
• Step 2 – Using CHMOD make the bash file executable
• Step 3 – To run the script navigate to the folder where the script is and type a ./ in front of the file name to execute.
BASH Syntax
#!/bin/bash (always goes at the very top)
echo "Hello, World“ (echo is used to present text)
BASH Variables
Inputvar1=“boo” (note no spaces)echo $var1 (note the dollar sign in front to use it)Outputboo
var1=0 (this would be a number; since there are no quotes)
BASH Inputs
read is the keyword to get the user input
Exampleread var1echo $var1
OutputWhatever the person typed in.
IF Statements
• if [something]• then• elif• then• elif• then• else• fi
• echo "Please enter type of fruit" • read fruit • if [ $fruit = apple ] • then echo "Good, I like Apples" • else echo "Oh no, I hate Oranges!" • fi
• #1 Create a script called userinfo that takes input (username) from a user and outputs the users information to the screen.
• #2 Create a script that outputs the difference between two numbers received from a user.
• #3 Create a script that will go to a text document with a list of users and create new user for each member in the list. You will also need to create a password for them and set it so they need to change their password no the next login. Set the password to expire after 3 months.
• Hint: You will need a loop for the last one.