From owner-freebsd-questions@FreeBSD.ORG Sun Oct 12 08:49:32 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BED301065678 for ; Sun, 12 Oct 2008 08:49:32 +0000 (UTC) (envelope-from jdc@koitsu.dyndns.org) Received: from QMTA05.emeryville.ca.mail.comcast.net (qmta05.emeryville.ca.mail.comcast.net [76.96.30.48]) by mx1.freebsd.org (Postfix) with ESMTP id A28248FC13 for ; Sun, 12 Oct 2008 08:49:32 +0000 (UTC) (envelope-from jdc@koitsu.dyndns.org) Received: from OMTA01.emeryville.ca.mail.comcast.net ([76.96.30.11]) by QMTA05.emeryville.ca.mail.comcast.net with comcast id Rkp21a0040EPchoA5kpYHy; Sun, 12 Oct 2008 08:49:32 +0000 Received: from koitsu.dyndns.org ([69.181.141.110]) by OMTA01.emeryville.ca.mail.comcast.net with comcast id RkpX1a0032P6wsM8MkpXpz; Sun, 12 Oct 2008 08:49:32 +0000 X-Authority-Analysis: v=1.0 c=1 a=Eh7KCOXnlxcA:10 a=QycZ5dHgAAAA:8 a=gyjK1YFX08b2I4Lf2wIA:9 a=9vIJ9Fmty3mG1xeC6TUA:7 a=s0lhVQix7R7mP4uTPIlk44RNnKEA:4 a=EoioJ0NPDVgA:10 a=jgoaQNzrKcYA:10 a=LY0hPdMaydYA:10 Received: by icarus.home.lan (Postfix, from userid 1000) id 50384C9419; Sun, 12 Oct 2008 01:49:31 -0700 (PDT) Date: Sun, 12 Oct 2008 01:49:31 -0700 From: Jeremy Chadwick To: Matthew Seaman Message-ID: <20081012084931.GA84974@icarus.home.lan> References: <7708.70177.qm@web56801.mail.re3.yahoo.com> <48F1B87E.6010803@infracaninophile.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <48F1B87E.6010803@infracaninophile.co.uk> User-Agent: Mutt/1.5.18 (2008-05-17) Cc: mdh_lists@yahoo.com, Gary Kline , FreeBSD Mailing List Subject: Re: rsync or even scp questions.... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Oct 2008 08:49:32 -0000 On Sun, Oct 12, 2008 at 09:42:38AM +0100, Matthew Seaman wrote: > mdh wrote: >> --- On Sat, 10/11/08, Gary Kline wrote: >>> On the Ubuntu computer I am /home/kline; on my main >>> computer, >>> my home is /usr/home/kline. The following sh script >>> worked >>> perfected when my home on "tao" [FBSD] was >>> /home/kline: >>> >>> P >>> #!/bin/sh >>> >>> PWD=`pwd`; >>> echo "This directory is [${PWD}]"; >>> >>> scp -qrp ${PWD}/* ethos:/${PWD} >>> ###/usr/bin/scp -rqp -i /home/kline/.ssh/zeropasswd-id >>> ${PWD}/* \ klin >>> e@ethos:/${PWD} >>> >>> Question #1: is there any /bin/sh method of getting rid of >>> the >>> "/usr"? I switch off between my two computers >>> especially when >>> get mucked up, as with my upgrade to kde4. (Otherwise, I >>> do >>> backups of ~kline as well as other critical directories.) >>> >>> Is there a way of automatically using rsync rather that my >>> kwik-and-dirty /bin/shell script? >>> >>> thanks, people, >>> >>> gary >> >> If what you wish to do is simply get rid of /usr in a string, you can use sed like so: >> varWithoutUsr=`echo ${varWithUsr} |sed -e 's/\/usr//'` >> After running this, where $varWithUsr is the variable containing a >> string like "/usr/home/blah", the variable $varWithoutUsr will be equal >> to "/home/blah". I create simple scripts like this all the time to >> rename batches of files, for example. >> >> The easier way is probably just to not specify a dir to scp's remote >> path though, since it defaults to the user's home directory. > > Or, in anything resembling Bourne shell: > > varWithoutUsr=${varWithUsr#/usr} And I'll take a moment to recommend Matthew's method, since it does not involve fork()ing an additional process. When writing shell scripts in general, it's best if you can avoid spawning external processes for things which can be done easily (keyword: easily!) within Bourne natively. There's no harm in doing it for more complex things, but fork() is somewhat expensive, and try to imagine what will happen to those scripts if the system lacks process table space, etc... :-) Best to try and make everything "self-contained" if possible. -- | Jeremy Chadwick jdc at parodius.com | | Parodius Networking http://www.parodius.com/ | | UNIX Systems Administrator Mountain View, CA, USA | | Making life hard for others since 1977. PGP: 4BD6C0CB |