Verbosity of command output

Lastly, when running a shell script, you will see output from the commands in the script (unless you want to remove that output with redirection, which will be explained in Chapter 12Using Pipes and Redirection in Scripts). Some commands are verbose by default. Good examples of these are the ls and echo commands: their entire function is to print something on screen.

If we circle back to the tar command, we can ask ourselves if we need to see all the files that are being archived. If the logic in our script is correct, we can assume the correct files are being archived and a list of these files will only clutter up the rest of the output from the script. By default, tar does not print anything; we have used the -v/--verbose option for this up until now. But, for a script, this is often not desirable behavior, so we can safely omit this option (unless we have a good reason not to).

Most commands have appropriate verbosity by default. The output of ls is printed, but tar is hidden by default. For most commands, it is possible to reverse the verbosity by using either a --verbose or --quiet option (or the corresponding shorthands, often -v or -q). A good example of this is wget: this command is used to grab a file from the internet. By default, it gives a lot of output about the connection, hostname resolution, download progress, and download destination. Many times, however, all these things are not interesting at all! In this case, we use the --quiet option for wget, because for that situation that is the appropriate verbosity of the command.

When shell scripting, always consider the verbosity of the commands you are using. If it is not enough, check the man page for a way to increase the verbosity. If it is too much, check that same man page for a quieter option. Most commands we have encountered have either or both options present, sometimes in different levels (-q and -qq for even quieter operation!).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.80.15