Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a bash script (exclusively using a single use of the utility ls and bash script constructs; no awk, sed, Perl, Python, etc.) that does

Write a bash script (exclusively using a single use of the utility ls and bash script constructs; no awk, sed, Perl, Python, etc.) that does the following when executed.

(a) It prints the names of all regular files (that is, not directories) that are readable, writable, and executable by the user in the current directory, one file name per line. It does not explore any subdirectories. Nothing other than the file name should be printed in these lines.

(b) After printing all the file names, the script prints the number of files printed in the earlier steps with proper annotation as given in the example that appears later.

If you use additional Linux commands or a different language, you will not receive any credit for this problem.

Suppose the directory appears as below.

-rw-r--r-- 1 cfs264sp170225 cfs264sp1702 21 2017-04-16 d1

drwxr-xr-x 2 cfs264sp170225 cfs264sp1702 4096 2017-04-16 dir1

-rw-r--r-- 1 cfs264sp170225 cfs264sp1702 181 2017-04-16 lsfile

-rwxr-xr-x 1 cfs264sp170225 cfs264sp1702 179 2017-04-16 p1

-rwxr-xr-x 1 cfs264sp170225 cfs264sp1702 14 2017-04-16 p2

-r--r-xr-x 1 cfs264sp170225 cfs264sp1702 828 2017-04-16 signindata

-rw-r--r-- 1 cfs264sp170225 cfs264sp1702 210 2017-04-16 x

The following would be the effect of the execution. Note that the file, when given adequate permission should be executable as below.

$ ./p1

p1

p2

Number of files 2

The only Linux command you are allowed to use in the bash script is ls with no options. All other functionality must be accomplished using bash constructs. The command (if stored in a file named p1) should work when invoked as

$ ./p1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions