From owner-freebsd-questions@FreeBSD.ORG Sat Jul 17 10:21:32 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7B9A116A4CE for ; Sat, 17 Jul 2004 10:21:32 +0000 (GMT) Received: from smtp.infracaninophile.co.uk (ns0.infracaninophile.co.uk [81.2.69.218]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6B7DD43D1D for ; Sat, 17 Jul 2004 10:21:28 +0000 (GMT) (envelope-from m.seaman@infracaninophile.co.uk) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost.infracaninophile.co.uk [IPv6:::1])i6HALMOa029498 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 17 Jul 2004 11:21:22 +0100 (BST) (envelope-from matthew@happy-idiot-talk.infracaninophile.co.uk) Received: (from matthew@localhost)id i6HALMjR029497; Sat, 17 Jul 2004 11:21:22 +0100 (BST) (envelope-from matthew) Date: Sat, 17 Jul 2004 11:21:22 +0100 From: Matthew Seaman To: Kathy Quinlan Message-ID: <20040717102122.GA29361@happy-idiot-talk.infracaninophile.co.uk> Mail-Followup-To: Matthew Seaman , Kathy Quinlan , Freebsd-Questions References: <40F8E457.1030303@kaqelectronics.dyndns.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZPt4rx8FFjLCG7dd" Content-Disposition: inline In-Reply-To: <40F8E457.1030303@kaqelectronics.dyndns.org> User-Agent: Mutt/1.5.6i X-Greylist: Message not sent from an IPv4 address, not delayed by milter-greylist-1.5.3 (smtp.infracaninophile.co.uk [0.0.0.0]); Sat, 17 Jul 2004 11:21:23 +0100 (BST) X-Virus-Scanned: clamd / ClamAV version devel-20040705, clamav-milter version 0.74a on smtp.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, hits=-4.8 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=2.63 X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on happy-idiot-talk.infracaninophile.co.uk cc: Freebsd-Questions Subject: Re: string manipulation in a shell script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jul 2004 10:21:32 -0000 --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--