Question: BASH SCRIPT IN LINUX Write a script named long_file.sh to find the longest file name in a directory. long_file.sh will accept a directory name as
BASH SCRIPT IN LINUX Write a script named long_file.sh to find the longest file name in a directory. long_file.sh will accept a directory name as the first argument and determine the longest filename in that directory. If the correct number of arguments are not provided, print an error message to standard output and exit the script with a return error of 1. If the scripts's first argument is not a directory name, print an error message to standard output and exit with a return code of 1. If a the first argument is a directory, print the directory name prior to printing the longest filename and length.
If there are multiple files with the same length, you need to print all the files if there are multiple files names with the same greatest length. A Bash array is good choice for storing multiple filenames. Example run: $ ./long_file.sh /home/michelle/temp Directory: /home/michelle/temp Longest filename: longerfilenameishere Longest filename len: 20 Directory listing from test directory $ ls /home/michelle/temp file1 file2 file3 file4 longerfilenameishere Example run 2: $ ./long_file.sh Usage: ./long_file.sh directory Example run 3: $ ./long_file.sh file1 First parameter must be a directory (file)
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
