Re: Could alias include the condition structure?



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 close
with a double.

function Test That is a non-standard syntax. The portable syntax for defining a
function 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

.



Relevant Pages

  • Re: Could alias include the condition structure?
    ... I want to use the alias as the macro in the function. ... "entry", it was working fine. ... Aliases are not expanded when the shell is not interactive, ... test1; ...
    (comp.unix.shell)
  • Re: Installing TeXLive 2004 on Mac OS X
    ... > Axel Kielhorn wrote: ... ~/.bashrc is read everytime the shell is invoced as a non-login shell, ... > alias cp='cp -vi' ... What is the result of "echo $SHELL"? ...
    (comp.text.tex)
  • Re: re-define type command
    ... echo is a shell builtin ... print is a shell builtin ... On ksh, type is an alias for "whence -v", so you first need to ...
    (comp.unix.shell)
  • Re: echo --help ?
    ... And try not to use the alias for "echo" built in to your ... But if normally you use the alias in your shell, ...
    (comp.os.linux.misc)
  • Re: take file name from command line arguement and write to file
    ... the Bourne Again Shell. ... > echo $a ... splitting, parameter substitutions etc. ... script and first sees the eval command, at first it behaves the usual ...
    (comp.unix.shell)