[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Re: Help with a bash script please



In <[🔎] 4D303AC4.2020909@chello.at>, Mart Frauenlob wrote:
>On 14.01.2011 11:37, Adrian Levi wrote:
>> I have (hopefully) taken on everybody's suggestions, Here is the
>> current script :)
>> 
>> 
>> #!/bin/sh
>> 
>> # Variables:
>> # Determine backup level
>> incrementalfile="/srv/tar_incremental_file"
>> 
>> if [ -f $incrementalfile ]
>> then
>> backuplevel="date +%w"
>
>backuplevel="`date +%w`"
>or:
>backuplevel="$(date +%w)"

Not required.  Word splitting is not preformed on the result of the subshell 
expansion in a variable assignment.  (Various expansions but NO WORD SPLITTING 
is done to the token that is the RHS of an EQUAL_SIGN recognized as part of a 
variable assignment, so double-quotes are rarely needed there.)

>> else
>> backuplevel="0"
>> rm $incrementalfile>  /dev/null 2>&1
>
>always quote file names with double quotes.
>put a space before the redirection.

# Aye.
rm "$incrementalfile" >/dev/null 2>&1

>> fi
>> 
>> zparameters="a -si -mhe=on -ppassword -t7z -m0=lzma -mx=9 -mfb=64
>> -md=32m -ms=on -l"
>> zfilename="Daily backup - $(date +"%a %h %H%M
>> %d-%m-%Y").$backuplevel.tar.7z" backuppath="/srv/allsocool /etc"
>> backupslocation="/srv/backups"
>> 
>> tarparameters="cf - --listed-incremental=$incrementalfile"
>> 
>> 
>> # cd to directory for output file
>> cd $backupslocation
>
>quotes.

# Aye.
cd "$backupslocation"

>> #tar $tarparameters $backuppath | 7z $zparameters $zfilename
>
>quote path and filename.

It's a comment, so quoting is rather pedantic.

>> tar $tarparameters $backuppath | 7z a -si test.tar.7z
>
>quote path and filename.

tarparameters needs to be word split before getting to the command, so we 
don't want to quote that.  Same thing is true for backuppath.  (I hope the OP 
never need to add a path containing whitespace to backuppath, you'll find it a 
bit futile.)
-- 
Boyd Stephen Smith Jr.                   ,= ,-_-. =.
bss@iguanasuicide.net                   ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy         `-'(. .)`-'
http://iguanasuicide.net/                    \_/

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: