rsync or even scp questions....

Oliver Fromme olli at lurza.secnetix.de
Thu Oct 16 07:42:18 PDT 2008


Why was this posted to -stable?  Anyway ...

Andrew D <andrewd at webzone.net.au> wrote:
 > 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:

I always create symlinks from /home to /usr/home or vice
versa, so both of them always work.

 > ~kline   is an alias for the home directory for the user kline.  You can 
 > use that in your scripts rather than the full path :)
 > As far as I know it works in all *nix variants.

It's not a matter of the UNIX variant, it's a matter of
the shell.  Most shells support the "~" tilde expansion
(FreeBSD's sh, csh, and shells from ports such as bash,
ksh and zsh).

However, I still recommend to use $HOME instead inside
scripts for portability reasons.  For example, Solaris'
/bin/sh does _not_ support "~".  $HOME always works.

 > > #!/bin/sh
 > > 
 > > PWD=`pwd`;
 > > echo "This directory is [${PWD}]";
 > > 
 > > scp -qrp  ${PWD}/* ethos:/${PWD}

Many superfluous characters.  You can make it shorter:

scp -qrp  $PWD/* ethos:$PWD

 > > ###/usr/bin/scp -rqp -i /home/kline/.ssh/zeropasswd-id ${PWD}/* \ klin
 > > e at 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.)

The easiest way is to make a symlink from /usr/home to
/home, as explained above.

To answer your actual question:  You can use "#" to
remove a prefix in /bin/sh scripts:

$ foo=/usr/home/whatever
$ echo ${foo#/usr}
/home/whatever

If the variable doesn't have a matching prefix, the
result remains unchanged.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"Software gets slower faster than hardware gets faster."
        -- Niklaus Wirth


More information about the freebsd-stable mailing list