Count Empty Lines in Shell Script

0% found this document useful (0 votes)
159 views1 page
The document provides instructions for writing a shell script that counts empty lines in a file passed as a command line argument. The script must validate: 1) the correct number of argument…

Uploaded by

raj sharma
  • Shell Script Instructions

In the file script.

sh, write a shell script to find the count of empty lines in a


given file. The filename will be given as command line argument. Incorporate the
following validations in the script : i. Whether correct number of command line
arguments are passed while running the script or not. ii. Whether the given input
file exists or not. [Link] the given input file is an ordinary file or not.
iv. Whether the given input file is readable or not. Print appropriate messages in
each case as per the messages shown in the example below. To save your code, please
press Ctrl+S in the project explorer. Examples : Note : Please refer to the files
in the project explorer for understanding the below examples. i. If the script is
executed as bash [Link], the output should be Pass appropriate number of command
line arguments ii. If the script is executed as bash [Link] [Link] where
[Link] is the input file then, the output should be Input file does not exist iii.
If the script is executed as bash [Link] myDir where myDir is the input file,
but myDir is a directory file not an ordinary file, then, output should be Input
file is not an ordinary file iv. If the script is executed as bash [Link]
testfile where testfile is the input file, but testfile does not have read
permission, then, the output should be Input file does not have read permission v.
If the script is executed as bash [Link] [Link] where [Link] is the input
file , then the output should be 0 vi. If the script is executed as bash [Link]
[Link] where [Link] is the input file , then the output should be 5
Note : Please print the exact messages as shown in the examples in your script. If
you do not use the exact message the test cases will not pass. Once you have
completed writing your code, you can click on Run -> Run Server to check the output
of your script. You can also try to execute your script from the command prompt by
clicking on the New terminal button on the right side top corner of the project
explorer. Also, you can check the status of the test cases by clicking on Run - >
Test. The status of the test cases will be shown on the terminal. Please check the
file [Link] for additional details of the test cases.

In the file script.sh, write a shell script to find the count of empty lines in a 
given file. The filename will be given as

You might also like