Date: Sat, 17 Jul 2004 11:21:22 +0100 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: Kathy Quinlan <kat-free@kaqelectronics.dyndns.org> Cc: Freebsd-Questions <freebsd-questions@freebsd.org> Subject: Re: string manipulation in a shell script Message-ID: <20040717102122.GA29361@happy-idiot-talk.infracaninophile.co.uk> In-Reply-To: <40F8E457.1030303@kaqelectronics.dyndns.org> References: <40F8E457.1030303@kaqelectronics.dyndns.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--ZPt4rx8FFjLCG7dd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jul 17, 2004 at 04:33:27PM +0800, Kathy Quinlan wrote: > Hi guys and Gals, >=20 > I have a simple script: >=20 > #!/bin/sh >=20 > a=3Dia$(date +%d%m%Y) >=20 > tar -cf "$a.zip" "/usr/home/projects/lunaria/items all" > mv $a.zip /usr/home/itemsall/ >=20 > this nearly does what I want, I would like to put the time in the file=20 > name aswell. If I put the %T in the date variable, the resultant value=20 > for $a has : seperating the hours, minutes and seconds. >=20 > Try as I might, I can not find away to remove the : and tar spits the=20 > dummy at them and it causes an IO device error. >=20 > I looked through sed and awk, and spent an hour playing, but all to no=20 > avail. >=20 > Anyhelp apreciated, Well, to get date(1) to spit out a date-time string without any unfortunate punctuation, try something like: % date +%Y%m%d%H%M%S See strftime(3) for details of all the % escapes you can use with date(1). On the other hand, tar(1) has an option --force-local which causes it to ignore colons in filenames as indicating a remote tape drive. Nb. that's gnu tar, which is the standard tar in all 4.x and any 5.x-RELEASE -- 5.2-CURRENT will shortly switch to bsdtar, and that will probably work differently. Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks Savill Way PGP: http://www.infracaninophile.co.uk/pgpkey Marlow Tel: +44 1628 476614 Bucks., SL7 1TH UK --ZPt4rx8FFjLCG7dd Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQFA+P2iiD657aJF7eIRAi8NAKCf1vhLTqgp06eU5MMU4HpelGguhgCfYuwl Q/74jIeRWuFDXdNDC/z2KjQ= =Khiz -----END PGP SIGNATURE----- --ZPt4rx8FFjLCG7dd--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040717102122.GA29361>