Bash Script Basics (Shell Scripting for Beginners)
Recently, I helped a client with the following project:
Script1 - script1.sh
1. The script creates in the current directory a subdirectory MY_DIR and then displays a message MY_DIR directory created. (including the full stop).
2. Then in the directory MY_DIR it creates a subdirectory My_dir and displays a message MY DIR/My_dir directory created. (including the full stop).
3. In My_dir it creates 15 ASCII text files named fileA_1, fileA_15 . The content of fileA_1 consists of two lines: the first saying File f ileA_1 and the second saying Next file fileA_2 . The content of fileA_2 consists of two lines File fileA_2 and Next file fileA_3 etc. Note that the last file fileA_15 contains two lines, the first saying File fileA_15 and the second saying No successor (most of the files ought to be created in a loop).
4. Then the script displays a message Regular files of subdirectory My_dir of directory MY_DIR: and then displays the names of all the regular files in My_dir (note that names of the non-regular files are not to be displayed, and since the ls command displays all entities in the directory, you cannot use 1 s for this purpose).
5. Then the script displays a message Created files contents : and then it displays the contents of all the created files in My_dir. The contents of each file is displayed after the name of that file was dipslayed followed by a colon (this ought to be done in a loop).
This example shell script / bash script is a great homework assignment for understanding the basics of bash and the power of programmatic scripting.
script1.sh is available on my GitHub!
Follow me for more cool projects!
Tags:
Bash, Script1.sh, shell, scripts, shell