[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bash question
From: |
Greg Wooledge |
Subject: |
Re: Bash question |
Date: |
Tue, 10 Mar 2009 08:14:30 -0400 |
User-agent: |
Mutt/1.4.2.2i |
On Sun, Mar 08, 2009 at 03:56:30PM -0700, jenea wrote:
> This is my script:
> =================================================================
> #!/bin/bash
> today_day=$(echo `date +"'%e %b %Y'"`)
>
echo `...` is usually redundant. In this case, it definitely is. You
only need:
today_day=$(date "+%e %b %Y")
You don't need (or want!) those literal single quotes in the data either.
> echo $today_day
>
> tar -cvz --newer $today_day -f /mnt/usb_backup/backup/diff/backupFull_`date
> +%Y%m%d`.tgz /mnt/mirror80gb/Shared_Folder/
Missing quotes. Your today_day variable contains data with spaces, so
if you want it to be passed as a single argument to tar, you must quote
it.
tar -cvz --newer "$today_day" -f ...
> + tar -cvz --newer ''\''25' Mar '2009'\''' -f
> /mnt/usb_backup/backup/diff/backupFull_20090325.tgz
> /mnt/mirror80gb/Shared_Folder/
> tar: Failed to open '/dev/sa0': Operation not supported
> filer:/mnt/usb_backup/backup/test#
Here you see where it fails because of your two problems: extra
single quotes in the data, and failure to quote the parameter expansion
in order to treat it as a single word.
The -f option appears (from tar's point of view) after the "Mar" and
"2009'" arguments, which tar assumes are files/directories, so tar
stopped processing arguments at that point. Therefore it didn't see
"-f foo.tgz" as an output file, and therefore it used /dev/sa0 as
its output file (which I presume is your OS's default).
today_day=$(date "+%e %b %Y")
tar -cvz --newer "$today_day" -f ...
That should fix it.
- Bash question, jenea, 2009/03/10
- Re: Bash question,
Greg Wooledge <=