|
Scripts are files that contain shell commands which may be short or can be very complex. Scripts just make it easier because you can invoke one command to run all of the commands in the script. Here instead of using 8 separate commands you can use one command to execute all of them.
This course is in a series of mini-courses to help you with Bash Shell Scripting. It is divided into several sections as you can see below. In addition, to help you in the challenge of learning bash shell scripting you will find a quiz at the end of each mini-course. Bash Shell: Basics Bash Shell: vi Text Editor Bash Shell: Nano Text Editor Bash Shell: Scripting Basics Bash Shell: Regular Expressions Bash Shell: Text Filters
This course will help you start to actually write your own Bash Shell scripts by providing some basic examples and explanations of how they work.
Course Difficulty The course level is for the inexperienced Linux User / Administrator. The focus is to provide a foundation for starting with the Bash Shell Scripting and a basis for the courses that will follow.
Course Outline Bash Scripts Script Anatomy Variables Back Tics Wildcards Exit Codes Functions Positional Parameters Testing Flow Control For Loop While Loop Case Statement Conditions Quiz
Lesson 2
t1.sh
#!/bin/sh cd /etc echo "################################" echo "All configuration files" ls *.conf echo "################################" echo "Files changed in last 3 days" find /etc -iname '*.conf' -mtime -3 exit
If you create a shell script it may be run by typing:
source scriptname
or
You need to modify the script so it has the ability to execute by using chmod:
chmod 755 scriptname
or
chmod +x scriptname
Without making this modification the script will deny you access to execute the command.
When you use the source command the script executes as if the command were in your login session. However, if you use the name only to execute the command if will run a copy of the shell as a subprocess which runs the command, terminates and then returns the control back to the parent shell.
Copyright CyberMontana Inc. and BeginLinux.com
All rights reserved. Cannot be reproduced without written permission. Box 1262 Trout Creek, MT 59874
|