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

Re: Help with a bash script please



Am 14. Jan, 2011 schwätzte Adrian Levi so:

moin moin,

I have the following bash script and it fails at line 14 and 15
(7zparameters= and 7zfilename=) I have tried everything i can think of
to get it to work, the answer has to be simple but i can't figure it.

7zparameters='a -si -mhe=on -ppassword -t7z -m0=lzma -mx=9 -mfb=64
-md=32m -ms=on -l'
7zfilename='Daily backup - `date +%a" "%h" "%H%M"
"%d-%m-%Y`.$backuplevel.tar.7z'

Make sure they're not two lines in your original file as they came across
in email to me.

For 7zfilename you need to use double-quotes. The double-quotes are needed
to use the $backuplevel variable and also in order to use command
substitution.

Also, I recommend to use $( ) rather than `` for command substitution. The
$( ) syntax will also protect the double-quotes being used for the date
command.

In the date command you should quote the entire format string rather than
just the spaces. Less work for you, easier to read for us :).

7zfilename="Daily backup - $(date +"%a %h %H%M %d-%m-%Y").$backuplevel.tar.7z"

tar $tarparameters $backuppath | 7z '$7zparameters' '$7zfilename'

You also need double-quotes in order for those variables to expand.

ciao,

der.hans
--
#  http://www.LuftHans.com/        http://www.LuftHans.com/Classes/
#  ABLEconf - 2011Apr02 - CfP 2011Jan22 - Free Software for Free Enterprise
#  "I never let schooling get in the way of my education." -- Mark Twain

Reply to: