Passing parameters to functions
Earlier within this chapter, we referred to functions as scripts within scripts and we will still maintain that analogy. Similar to how a script can have input parameters, we can create functions that also accept parameters that can make their operation less static. Before we work on a script, we can look at a useful function in the command line.
Note
One of my pet peeves is overcommented configuration files, especially where documentation exists to detail the options available.
The GNU's Not Unix (GNU) Linux sed
command can easily edit the file for us and remove commented lines and empty lines. We are introducing the stream editor, sed
, here but we will look at it in more detail in the following chapter.
The sed
command line that runs the in-place edit will be as follows:
$ sed -i.bak '/^\s*#/d;/^$/d' <filename>
We can run out forensics in the command line by breaking it down element by element. Let's take a deeper look:
sed -i.bak
: This edits the file and...