Mastering Linux Shell Scripting by Andrew Mallett

Mastering Linux Shell Scripting by Andrew Mallett

Author:Andrew Mallett [Mallett, Andrew]
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2015-12-23T23:00:00+00:00


We have provided two functions within the script. The first, is_file, simply tests to ensure that the filename we have entered is a regular file. Then we declare the clean_file function with a little added functionality, displaying the line count of the file before and after the operation. We can also see that functions can be nested and we call the is_file function with clean_file.

Without the function definitions we have only three lines of code at the end of the file that we can see in the example code laid out in the previous code block and has been save as $HOME/bin/clean.sh. We first prompt for the filename and then run the clean_file function, which in turn calls the is_file function. The simplicity of the main code is important here. The complexity is in the functions, as each function can be worked on as a standalone unit.

We can now test the script operation, first using a wrong filename, as we can see in the following screenshot:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.