scripting cbis 4225. bash scripting step 1 – create the bash file. usually a good idea to end it...
TRANSCRIPT
![Page 1: Scripting CBIS 4225. BASH Scripting Step 1 – Create the bash file. Usually a good idea to end it in.sh file1.sh Step 2 – Using CHMOD make the bash file](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649dd15503460f94ac76dc/html5/thumbnails/1.jpg)
Scripting
CBIS 4225
![Page 2: Scripting CBIS 4225. BASH Scripting Step 1 – Create the bash file. Usually a good idea to end it in.sh file1.sh Step 2 – Using CHMOD make the bash file](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649dd15503460f94ac76dc/html5/thumbnails/2.jpg)
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.
![Page 3: Scripting CBIS 4225. BASH Scripting Step 1 – Create the bash file. Usually a good idea to end it in.sh file1.sh Step 2 – Using CHMOD make the bash file](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649dd15503460f94ac76dc/html5/thumbnails/3.jpg)
BASH Syntax
#!/bin/bash (always goes at the very top)
echo "Hello, World“ (echo is used to present text)
![Page 4: Scripting CBIS 4225. BASH Scripting Step 1 – Create the bash file. Usually a good idea to end it in.sh file1.sh Step 2 – Using CHMOD make the bash file](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649dd15503460f94ac76dc/html5/thumbnails/4.jpg)
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)
![Page 5: Scripting CBIS 4225. BASH Scripting Step 1 – Create the bash file. Usually a good idea to end it in.sh file1.sh Step 2 – Using CHMOD make the bash file](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649dd15503460f94ac76dc/html5/thumbnails/5.jpg)
BASH Inputs
read is the keyword to get the user input
Exampleread var1echo $var1
OutputWhatever the person typed in.
![Page 6: Scripting CBIS 4225. BASH Scripting Step 1 – Create the bash file. Usually a good idea to end it in.sh file1.sh Step 2 – Using CHMOD make the bash file](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649dd15503460f94ac76dc/html5/thumbnails/6.jpg)
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
![Page 7: Scripting CBIS 4225. BASH Scripting Step 1 – Create the bash file. Usually a good idea to end it in.sh file1.sh Step 2 – Using CHMOD make the bash file](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649dd15503460f94ac76dc/html5/thumbnails/7.jpg)
• #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.