Can anyone explain?

Stanley Friesen friesen at psivax.UUCP
Sat Aug 3 08:19:43 AEST 1985


In article <118 at wgivax.UUCP> ram at wgivax.UUCP (Rick Messinger #4975) writes:
>
>  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.

	Well, the problem is not the design of the shell, it is the
design of the kernel! The current directory is an attribute of a
*process*, not a user or login session, and as such it may only be
passed *downwards* to children, not upwards to the parent. Thus even
a C program would fail, since it also would run as a child process.
The solution is to get the command sequence interpreted directly by
the interactive shell rather than in a sub-shell. Csh has two ways
of doing this, "alias" and "source". For something like this I
usually combine both. That is I set up an alias to "source" the script.
Unfortunately, the sh equivalent of "source", the "." command, does
not pass arguments to the script being interpreted, so it will not
work, and shell variable expansion does not provide for arguments
either, so you have no general equivalent of the alias feature!
-- 

				Sarima (Stanley Friesen)

{trwrb|allegra|cbosgd|hplabs|ihnp4|aero!uscvax!akgua}!sdcrdcf!psivax!friesen
or {ttdica|quad1|bellcore|scgvaxd}!psivax!friesen



More information about the Comp.unix mailing list