UNIX Assignment I Write a bash script ( without using loop ) that meets the foll
ID: 3591480 • Letter: U
Question
UNIX Assignment I
Write a bash script (without using loop) that meets the following requirements:
Do not use echo also
Name: The name of the script MUST be myls.sh
Location: The location of the script MUST be ~/bin/myls.sh
FUNCTIONALITY:
The script MUST be menu driven
The script MUST present five (5) options of the ls command
The script MUST prompt the user for input to select an option
The script MUST then process the option by executing the ls command with the option
The output of the executed command should display to std out
The script MUST be documented with comment statements
The script MUST use the decision or selection structure to interpret the user selection and gracefully handle an invalid selection.
The script must be tested for all valid and some invalid input
$myls.sh
1)R recursive listing
2)Option……
3)Option……
4)Option……
5)Option……
Enter selection>R
vinotes
Scripts: myscript.sh
……………….
Explanation / Answer
Copy the below lines in a new sh file named myls.sh, and movethe file to ~/bin or whatever location is desired:
#!/bin/bash
printf "%s " "1. R Recursive Listing"
printf "%s " "2. One column output"
printf "%s " "3. Sort by modification time"
printf "%s " "4. Long listing format"
printf "%s " "5. Sort by size"
read -p "Enter choice [ 1 - 5] " choice
case $choice in
1) ls -R ;;
2) ls -1 ;;
3) ls -t ;;
4) ls -l ;;
5) ls -S ;;
*) echo -e "${RED}Invalid Output...${STD}"
esac
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.