Can anyone explain?

Don McKillican don at hcrvx1.UUCP
Wed Jul 31 23:16:28 AEST 1985


>> : 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.

If your version of unix has shell functions, you could try something along
these lines:

	cpd() { cp $1 $2/$1 ; cd $2 ; }

This defines cpd as a shell function which executes the commands listed *within
the current shell*, rather than in a subshell.  This is documented in SH(1)
(page 2 in the System 5 documentation).

			Don McKillican @ Human Computing Resources Ltd.
			{ihnp4,decvax,utzoo,watmath}!hcr!hcrvx1!don



More information about the Comp.unix mailing list