Re: [SLE] Translating a BSD (c-shell) alias to Linux Bash
Thanks again for the suggestion. You've kept me persuing this! After experimenting, then reading the man pages for bash, I found out a couple things. Aliases don't allow for passing arguments. You are supposed to used shell funtions for that. O.K. Now how do I translate my command string into a shell function that works? tardy () { (cd $1; tar cf - .) | (cd $2; tar xpfS - ); } ?????? No. This completely fails, because piping doesn't appear to work in shell functions. (I really didn't expect it would.) In fact, this makes a horrible mess with tar trying to extract back into the source directory structure. So, How do I write a shell function to do what I want??? -Gerry linux@darykon.cet.com On Thursday 04 Sept 2003 Nick LeRoy wrote:
On Thursday 04 September 2003 6:07 pm, Linux Mailing lists account wrote:
I've fought with this for too long!
I have a favorite command for copying file structures on my BSD system. It's:
(cd !:1; tar cf - .) | (cd !:2; tar xpf -)
Well, I've never set it up as an alias, but at the shell I routinely do something like:
$ cd /some/dir; tar cf - . | ( cd /dest/dir; tar xvpfS - )
So, I'd think that you'd want to do something like:
alias tarcp='cd $1; tar cf - . | ( cd $2; tar xfpS - )'
Can someone, PLEASE, tell me how to translate this to bash?
Thanks!!
Hope this helps
-Nick
On Friday 05 September 2003 12:50 am, Linux Mailing lists account wrote:
Thanks again for the suggestion. You've kept me persuing this!
After experimenting, then reading the man pages for bash, I found out a couple things.
Aliases don't allow for passing arguments. You are supposed to used shell funtions for that.
O.K. Now how do I translate my command string into a shell function that works?
tardy () { (cd $1; tar cf - .) | (cd $2; tar xpfS - ); } ??????
No. This completely fails, because piping doesn't appear to work in shell functions. (I really didn't expect it would.) In fact, this makes a horrible mess with tar trying to extract back into the source directory structure.
So, How do I write a shell function to do what I want???
I don't know; I don't use them much (but maybe I should). How about just write it as a shell script? I know, it's lacking the glory and fun of solving the problem, *and* it's a wee bit slower, but it'll certainly work. :-) #!/bin/sh cd $1; tar cf - . | ( cd $2; tar xpfS - ) -NIck
Nick LeRoy <nleroy@cs.wisc.edu> [Fri, 5 Sep 2003 08:27:22 -0500]:
#!/bin/sh cd $1; tar cf - . | ( cd $2; tar xpfS - )
Quite :) I'd change it so: #!/bin/bash if [ ! -z "$1" -a ! -z "$2" -a "$1" != "$2" ]; then tar -C $1 -cSp --numeric-owner --atime-preserve -f - . | \ ( tar -C $2 -xSpv --atime-preserve -f - ) else echo "One or both of source and target directory is missing" echo "or source and target are identical" exit 1 fi or, as function tarx() { if [ ! -z "$1" -a ! -z "$2" -a "$1" != "$2" ]; then tar -C $1 -cSp --numeric-owner --atime-preserve -f - . | \ ( tar -C $2 -xSpv --atime-preserve -f - ) else echo "One or both of source and target directory is missing" echo "or source and target are identical" fi } See 'man tar' for a description of the tar options used and 'man test' for a description of the test options used. Philipp
participants (3)
-
Linux Mailing lists account
-
Nick LeRoy
-
Philipp Thomas