Make sure your scripts have Unix style line endings. See page with title “Script File Line Ending Caveat” of 6_shell_basics.pptx for details. If Folio complains, you can add .txt extension to the files. For example, myfile.sh.txt, makefile.txt. You don’t need to add .txt extension if Folio/Gradescope allows you to submit without complaining.
(15 pts) Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories separately in the directory that is specified as the first command line argument to this script. DO NOT count recursively in subdirectories. DO NOT call any external Linux utilities such as “ls”. You may refer to the testSearch.sh example and page 7 of the “Basic Bash Scripting Lab.docx” documentation in Folio to find out how to test if an item in a directory is an executable or non-executable file or subdirectory. You can test your script using “./A5p1.sh ” where can be any absolute (those starting with ‘/’) or relative directory (those not starting with ‘/’). A sample run can look like the following (You do NOT need to submit screen shots. Instead submit your source file.):
(15 pts) Write a bash script A5p2.sh that accepts one command line argument a which is assumed to be an integer no less than 2. Your script should output a list of integers starting from a and ending with 1 according to the iteration rule from assignment 4 problem 2 (f(x)=x/2 if x is even; f(x)=(3x 1)/2 if x is odd). After that, also report the number of integers in the list. Don’t call any external programs. Implement all algorithms in your script. You can test your script using “./A5p2.sh ”. A sample run can look like the following (You do NOT need to submit screen shots. Instead submit your source file.):
(15 pts) Write a bash script A5p3.sh to print all 16 binary 2 by 2 matrices in lexicographic order. You must use loops to achieve the desired printing results. The total number of times that the keyword for, while and until appear cannot exceed 6. Do not call any external programs in this script. Part of a sample run can look like the following:
(15 pts) Write a bash script A5p4.sh to print in lexicographic order all possible 2 by 2 matrices in which each element can be one of three or more distinct (lower case) English characters. The candidate English characters for the matrix elements should be provided by the user as the command line arguments (assume that the user will type in these characters in alphabetical order). You must use loops to achieve the desired printing results. The total number of times that the keyword for, while and until appear cannot exceed 6. Do not call any external programs in this script. A sample run can look like the following.
(30 pts) Write a bash script A5p5a.sh that accepts one command line argument which is supposed to be a positive integer n. The script should print all odd integers from 1 through n (each on a separate line). Write another bash script A5p5b.sh to read from stdin as many integers as there are available and then print the squares of all these integers (each on a separate line). You should test your code by “./A5p5a.sh | ./A5p5b.sh”. Submit both source code files. See the following for a sample run. (You do NOT need to submit screen shots. Instead submit your source files.)
(10 pts) Write a bash script A5p6.sh that accepts two command line arguments m and n (assumed to be positive integers with m<n). This script should call your bash script A5p2.sh with all integers from m through n inclusive. Make sure all output lists for these integers are clearly separated. You may refer to LaunchExternal.sh in Folio example codes. See the following for a sample run.
[kwang@computer][~/temp]$./A5p1.sh
Number of executable files in : 7
Number of non-executable files in : 6
Number of subdirectories in : 5
[kwang@computer][~/temp]$./A5p2.sh 6
6,3,5,8,4,2,1
Length of the list: 7
[kwang@computer][~/temp]$ ./A5p3.sh
0 0
0 0
0 0
0 1
0 0
1 0
…..(additional output here)
[kwang@computer][~/temp]$bash A5p4.sh a x z
a a
a a
a a
a x
…(additional output here)
z z
z z
[kwang@computer][~/temp]$bash A5p5a.sh 10 | ./A5p5b.sh
1
9
25
49
81
[kwang@computer][~/temp]$bash A5p6.sh 101 120
Here is the list beginning with 101:
101,152,76,38,19,29,44,22,11,17,26,13,20,10,5,8,4,2,1
Length of the list: 19
…(additional output here)
Here is the list beginning with 120:
120,60,30,15,23,35,53,80,40,20,10,5,8,4,2,1
Length of the list: 16
Checklist for seven files to be submitted: A5p1.sh, A5p2.sh, A5p3.sh, A5p4.sh, A5p5a.sh, A5p5b.sh, A5p6.sh.