What is the "Best Practice" When Using a Positional Parameter?
by Steve R. from LinuxQuestions.org on (#51QJH)
I have the following code snippet. This code snippet is essentially duplicated in several places for different uses.
Code:# Set Backup Log Name Extension
if [ $1 -eq 0 ]
then
log_extension="incremental_backup_log.txt"
backup_type="Incremental"
else
log_extension="full_backup_log.txt"
backup_type="Full"
fiI was wondering, as a "best practice", if the value of "$1" should be immediately assigned to a variable (at its first use) so that it ("$1") is not used again in the script. See example below.
Code:# Set Backup Log Name Extension
backup_style=$1
if [ backup_style -eq 0 ]
then
log_extension="incremental_backup_log.txt"
backup_type="Incremental"
else
log_extension="full_backup_log.txt"
backup_type="Full"
fi


Code:# Set Backup Log Name Extension
if [ $1 -eq 0 ]
then
log_extension="incremental_backup_log.txt"
backup_type="Incremental"
else
log_extension="full_backup_log.txt"
backup_type="Full"
fiI was wondering, as a "best practice", if the value of "$1" should be immediately assigned to a variable (at its first use) so that it ("$1") is not used again in the script. See example below.
Code:# Set Backup Log Name Extension
backup_style=$1
if [ backup_style -eq 0 ]
then
log_extension="incremental_backup_log.txt"
backup_type="Incremental"
else
log_extension="full_backup_log.txt"
backup_type="Full"
fi