Re: alias to the sub shell



On 2006-04-08, Dan Mercer wrote:

"dondora" <koninja@xxxxxxxxxxx> wrote in message news:1144311415.520033.223430@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
: thanks Chris.
: the shell I'm using is korn shell
: the procedure i did is
:
: $ alias -x dir='ls -al'
: $ ksh (goes into the subshell)

This is not a subshell, it's a brand new shell. Subshells
are created explicitly by the use of parentheses or by
command substitution. They are also created in pipelines
or by calling scripts without a shebang.

A script without a shebang is a new process, not a subshell.

FWIW, the use of aliases in scripts for anything other than
abbreviating a long path (and then should be aliased in the script)
is not a Best Practice. Aliases are useful interactively and
probably should be restricted to interactive use.

The bash man page says it best:

For almost every purpose, aliases are superseded by shell
functions.

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
.



Relevant Pages

  • Re: [opensuse] alias failure
    ... So it's just an accident that the following aliases all work as I ... It's uncommon for interactive shells to have any positional parameters ... Unlike the very limited capabilities of aliases, shell procedures ... I made a script with nothing but that in it, ...
    (SuSE)
  • Re: How can I get the value of a variable from within awk script into shell?
    ... I have to write a bash-shell script to process a file. ... I use in this shell script these awk ... This is more a shell problem than an awk problem. ... in a subshell, and this seems to be your case. ...
    (comp.lang.awk)
  • Re: Executing a command in sub-shell
    ... > script and only 1 line of output, ... which is expanded by the shell where it has not been set. ... > expand it dynamically in the subshell, it needs to be quoted in the here ... > its parent shell, so you're out of luck there. ...
    (comp.unix.shell)
  • Re: how to set timeout for read command
    ... > The shell is asked to do a number of things. ... This could take a very long time if the remote machine is not ... > Line 7 kills off the background subshell, ... forward quote before (sleep.... ...
    (comp.unix.shell)
  • Re: [opensuse] alias failure
    ... So it's just an accident that the following aliases all work as I want/expect? ... alias ll='ls -l $*' ... I made a script with nothing but that in it, ... the shell procedure. ...
    (SuSE)