BACKGROUND
I am reading Advanced Bash Scripting by Mendell Cooper. In this eBook there is a Chapter 16 External Filters, Programs and Commands. Within this chapter there is "Example 16-15. Using tail to monitor the system log".
INTRO
To create the file if it does not already exist, truncate it to zero length (if it exists) and to paste last ten lines of the file /var/log/messages to the aforesaid log file, the author chooses the below method:
TEXTBOOK
Code:
#NAME LOG FILE
filename=sys.log
#TRUNCATES LOG TO ZERO LENGTH
cat /dev/null > $filename; echo "Creating / cleaning out file."
#PASTE LAST TEN MESSAGES INTO LOG
tail /var/log/messages > $filename
But I use the following code line serving the same purpose:
ALTERNATE METHOD
Code:
#NAME LOG FILE
filename=sys.log
#PASTE LAST TEN MESSAGES INTO LOG (Using the ">" to write over the old input with new input).
tail /var/log/messages > $filename
ANALYSIS
Originally I thought: Isn't truncating the log to zero length by the command: '
Code:
cat /dev/null > $filename
superfluous being that on the last command a ">" is used and not a ">>"?
But then I remembered "Chapter 3. Special Characters", and on p17 under the Variable expansion/substring replacement section there is the following codeblock:
Code:
: > data.xxx
# File "data.xxx" now empty.
# Same effect as
cat /dev/null >data.xxx
# However, this does not fork a new process, since ":" is a builtin.
So it seems the author is merely trying to broaden our command line flexibility by not repeating the same commands too much.
QUESTION:
By the "fork a new process" sentence above, does this mean that the difference between these two commands is that
Code:
cat/dev/null >data.xxx
does fork a new process BUT
does NOT?