Overriding Parameter Expansion?

Lawrence V. Cipriani lvc at cbnews.ATT.COM
Thu Aug 25 23:13:31 AEST 1988


In article <810026 at hpsemc.HP.COM>, gph at hpsemc.HP.COM (Paul Houtz ) writes:
>    Does any one know if it is possible for a program or function to
>    tell whether the shell (especially csh or ksh) has expanded a 
>    parameter into multiple file names?

A UNIX(tm) program cannot determine how it's argument list was generated.
I don't know about csh.  For ksh you can use a combination on an alias and
a function to control filename generation.  For example:

	alias myfunc='set -f;_myfunc'
	function _myfunc
	{
		trap 'set +f' EXIT	# not sure of the exact syntax here
		...whatever...
	}

>    It would be nice if I could at least know that expansion has 
>    occurred in parameter 1.    

You'll have to be careful to check if * expands to * when there are no
matching filenames.

>    Note, I do NOT want to turn off parameter expansion (set -f) 
>    in my shell.  I also do NOT want to quote the parameters, e.g.,
>    I do not want to say myfunc "*" file2 file3.

This turns it off during the function execution and then turns it back on
when the function completes.  Good enough?

>    Since there are commands that will do the filename expansion for you,
>    doesn't it seem contrary to the basic idea of UNIX that this expansion
>    is done for you automatically by the shell?

I like it being in the shell primarily for consistency and secondarily
for efficiency.

>    Normally unix [sic] does not 
>    get in my way, but in this example it does.  I wouldn't mind if I had 
>    to expand my parameters myself.  I think I should be able to invoke
>    a function and have access to the raw parameters with a shell script.
>    (and more than 9, too.)  Oh well. 

With ksh you can access up to 99 arguments, and can get access to the 'raw'
parameters as I have shown.

-- 
Larry Cipriani, AT&T Network Systems, Columbus OH, cbnews!lvc lvc at cbnews.ATT.COM



More information about the Comp.unix.questions mailing list