[wplug] TAR Shell Question

Bob Schmertz rschmertz at speakeasy.net
Fri Mar 7 18:39:24 EST 2003


On 07 Mar 2003, Wise, Jeremey wrote:

> Here is the script that work:
>
> #!/bin/bash
> mount -t nfs 10.0.0.100:/home/test /mnt/cdrom
> mount -t nfs 10.0.0.100:/home/test1
> /mnt/floppy tar cf - -C /mnt/floppy . |tar
> -xvf - -C /mnt/cdrom
>
> Though this works I do not understand why this
> does not. tar -cf -C - /mnt/floppy . |tar -xvf
> -C - /mnt/cdrom
>

The "f" in your "-cf" option list means "output file", and must be immediately followed by the output file name, otherwise tar won't know which word in the command denotes the file it is supposed to write to.  In your case, you're using "-", which means "write to standard output rather than to a file", but again, it must come immediately after the "-cf" token, as in, "-cf -"; you can't have the -C in between those, otherwise it may interpret the -C token as the name of the output file.  In fact, you might want to check the directory where you were sitting when you ran this command, and see if you created a file called "-C".  If there is, you can remove it with 'rm ./-C'.

> This should be the better / working syntax as
> bash interperatest the "-" as "-" which (if
> you RTFMP) you read that
>
> " -- A -- signals the end of options and
> disables further option processing. Any
> arguments after the -- are treated as
> filenames and arguments. An argument of - is
> equivalent to --."

A lot of things are wrong here, but probably the biggest is that you're misinterpreting the context of that quote.  That reference to the meaning of "--" only applies to options passed to the /command/ "bash".  So if you want to start a new bash shell with "bash -a -b -c -- -d -e -f", then it'll interpret the a, b, and c options according to what it says in the man page, but it'll treat "-d", "-e", and "-f" just as miscellaneous strings (presumably it'll look for a script called "-d", and the other args will get thrown away).  But again, this only applies when you're running the bash command, which includes putting it in the first line of a script with a #! at the beginning.  Within a running bash shell, a "--" argument to another command is not treated specially by bash, and it's up to the command to decide how it wants to treat that.  Many standard utilities (esp. GNU utilites) do follow the same convention, though, so another way to remove the -C file I referred to would be "rm -- -C" (tells rm that -C is not an option, just a file).  Tar does not have any use for the "--", though -- but you didn't even use "--", just "-".  The bash /command/ may consider "-" to be equivalent to "--", but the bash /shell/ does not, and neither does tar.

-- 
Cheers,
Bob Schmertz



More information about the wplug mailing list