Re: Could alias include the condition structure?
- From: "sealo" <seahalo@xxxxxxxxx>
- Date: 31 Dec 2006 01:30:02 -0800
Sorry, I must apologize for the last carelessly log of the quote usage.
And, it's clear the alias are not expanded in the non-interactive
shell.
The question is:
I want to define an function, invoked be every other function at the
entry for debug usage. The function was used to echo the Function Name,
if the debug flag was true.
<code>
entry()
{
if [ $DEBUG_FLAG -eq 1 ]; then
# echo the parent function name.
fi
}
test1()
{
entry;
}
test2()
{
entry;
}
DEBUG_FLAG=1;
test1; # It will echo "test1"
test2; # It will echo "test2";
DEBUG_FLAG=0;
test1; # echo nothing
test2; # echo nothing
</code>
On 12月31日, 下午12时10分, "Chris F.A. Johnson"
<cfajohn...@xxxxxxxxx> wrote:
On 2006-12-31, sealo wrote:
Hello,
I want to use the alias as the macro in the function. But when I give
the "if; then fi" structure into the alias, the execution was failed.
The original code like this.
<code>
#!/usr/bin/bash:
alias entry='if [ $DEBUG -eq 1 ]; then echo $FUNCNAME; fi"; Your quotes are mismatched; you open with a single quote and closewith a double.
function Test That is a non-standard syntax. The portable syntax for defining afunction is:
Test()
{
entry;
# Other Something
}
</code>
The execution was report error. If I remove the if structure to the
"entry", it was working fine. How can I add the condition judgement in
the alias ? Note the bash man page:
Aliases are not expanded when the shell is not interactive,
unless the expand_aliases shell option is set using shopt (see
the description of shopt under SHELL BUILTIN COMMANDS below).
...
For almost every purpose, aliases are superseded by shell
functions.
...
Aliases are confusing in some uses.
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.
- References:
- Could alias include the condition structure?
- From: sealo
- Re: Could alias include the condition structure?
- From: Chris F.A. Johnson
- Could alias include the condition structure?
- Prev by Date: Re: Could alias include the condition structure?
- Next by Date: Re: How to change the password of root user by logging as normal user in linux
- Previous by thread: Re: Could alias include the condition structure?
- Next by thread: Re: How to make my terminal support color output?
- Index(es):
Relevant Pages
|