Can anyone explain?
M.J.Shannon
mjs at eagle.UUCP
Wed Jul 31 21:55:07 AEST 1985
>
> In this sh scipt is a sequence of two events.
>
> > : Copy a file to a directory then chdir to the given dir
> > case $# in
> > 2) cp $1 $2/$1 ; cd $2 ;;
> > *) echo 'Usage: ccarry file dir/path' ;;
> > esac
>
> Due to the design of the shell, it does not work (not in actuality anyway).
> Does anyone out there know of a way this can be done. I got word it could
> be done in C? I'll be interested to find out.
> Thanks for any info.
>
> (ram)
It *does* work, but it doesn't do what you want it to. The only way to get it
to do what you want is to have your shell (not a sub-shell) execute it. How,
you ask? Assuming you've called it "ccarry" and it lives in one of the
directories in your PATH, use it thusly:
. ccarry foo otherdir
The "." tells your shell to execute the script as though you had typed it at
the terminal. You must use this method for any shell script that does things
that intend to change the environment of the current shell (such as setting
variables). This is how your .profile is executed when you login.
It can also be done in C, but showing how is more than my not quite awake brain
is up to at this hour of the day. (MORE CAFFIENE!)
--
Marty Shannon
UUCP: ihnp4!eagle!mjs
Phone: +1 201 522 6063
More information about the Comp.unix
mailing list