Results 1 to 2 of 2
Hey guys... I'm a bit stuck, and hoping someone can help me out.
I wrote some bash code to prevent redundantly including files, like php's "include_once". I've simplified it here ...
- 07-13-2010 #1Just Joined!
- Join Date
- Jun 2010
- Posts
- 6
unalias not working?
Hey guys... I'm a bit stuck, and hoping someone can help me out.
I wrote some bash code to prevent redundantly including files, like php's "include_once". I've simplified it here so don't worry that it appears not to do anything:
For some reason this is not working. Although I "unalias source" inside the "Include" function, the very next line is still calling "Include". Here is what I see with set -v -x:Code:alias .='Include' alias source='Include' export __INC__functions=1 function Include { local name="__INC__"`basename ${1%\.*}` eval "export $name=1" unalias source source $1 alias source='Include' }
the unalias appears to work, but the next call to source is treated as the original alias. Does anyone know why it would do this? Are aliases replaced within a function at the start of the function, or perhaps when the function is defined? Is there a way to get this to work?Code:... ++ eval 'export __INC__mysql_functions=1' export __INC__mysql_functions=1 +++ export __INC__mysql_functions=1 +++ __INC__mysql_functions=1 ++ unalias source ++ Include /home/fonix/client_progs/cs/utils/mysql_functions.sh ...
Thanks in advance!
- 07-13-2010 #2Just Joined!
- Join Date
- Jun 2010
- Posts
- 6
I do see this in the MAN page which does explain the behavior:
"Aliases are expanded when a function definition is read, not when the function is executed, because a function definition is itself a compound command."
So I guess I'll just ask the last question I had. Is there a way around this?


Reply With Quote