Write a bash script file that tests each file entry in the current directory. It should...

80.2K

Verified Solution

Question

Programming

Write a bash script file that tests each file entry in thecurrent directory. It should determine if it is a file ordirectory. If it is a file, it will determine if it is readable ornot. If it is readable, it will display only the first 4 lines tothe terminal in sorted order (just sort the first 4 lines).
If it is a directory, it should display the contents of thatdirectory (the files and subdirectories).
NOTE: Please don’t use the read command or arguments with yourscript. Note that you don’t need to use either one of these methodsto get a list of files in the current directory.
=====================================
Example Output
Note that the output
from running the script starts at
the sixth line
=====================================
$ ls -l
total 32
drwxrwxr-x 3 cocofan cocofan 4096 Jan 20 17:58 adir
--w-rw-rw- 1 cocofan cocofan 128 Mar 15 22:43 lines.dat
-rw-rw-rw- 1 cocofan cocofan 48 Sep 5 2016 months.txt
$ bash assg5.sh
ENTRY IS adir
**This is a directory**
afileinadir.txt subdirofadir
ENTRY IS lines.dat
**This is a file**
...file is not readable.
ENTRY IS months.txt
**This is a file**
...and it's readable.
...it's first four lines in sorted order are:
Apr
Feb
Jan
Mar
$
++++++++++++++++++++++++++++++++++++

Answer & Explanation Solved by verified expert
4.1 Ratings (655 Votes)
Question Write a bash script file that tests each file entry in the current directory It should determine if it is a file or directory If it is a file it will determine if it is readable or not If it is readable it will display only the first 4 lines to the terminal in sorted order just sort the first 4 lines If it is a directory it should display the contents of that directory the files and subdirectories NOTE Please dont    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students