Re: Could alias include the condition structure?



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: [OT] Using aliases or functions in bash script
    ... How can I use my aliases or functions in my bash script? ... I have the following alias and function defined in my ~/.bashrc: ... shopt builtin. ... values of the shell options accepted by shopt are printed on ...
    (Debian-User)
  • Re: Learning C with Older books ?.
    ... Tim Rentsch wrote: ... This is enforced by use of an alias for gcc. ... Since my system make does not use the shell this ... which knows nothing about 4dos aliases (and vice ...
    (comp.lang.c)
  • Re: Learning C with Older books ?.
    ... Tim Rentsch wrote: ... This is enforced by use of an alias for gcc. ... Since my system make does not use the shell this ... which knows nothing about 4dos aliases (and vice ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Automating alias saving in bash
    ... Deleting aliases permanently requires editing .aliases ... AND you can't use "a" again unless you first unalias within the shell, ... Command "unalias -a" is handy for big changes. ... but you can use the original command "alias" for listing aliases. ...
    (comp.os.linux.misc)
  • Re: Ode to the Shell (Was: Re: which file manager you use?)
    ... >> In what file are the default aliases kept? ... > it's bash (the most likely shell for the modern linux user). ... [charles@moe charles]$ echo $SHELL ... $ alias ...
    (Fedora)