Re: Executing an alias inside a scritps



Barry Margolin wrote:
In article <1156936740.649889.96490@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
gfiuni2@xxxxxxxxx wrote:

There is a thing that I don't understand. The ".kshrc" file is executed
each time a new instance of ksh is started. Is not this the case when I
run a script?

By default, aliases are only expanded in interactive shells. When you run a script, the shell is non-interactive.


I don't believe this is accurate.
Aliases defined within the script are expanded.

What often is the case is whether the "$ENV" file, typically ~/.bashrc,
is automatically sourced when starting a non-interactive instance of ksh.

The intended, primary purpose for aliases is to assist in your interactive
shell session. For example, I like the protection of the "-i" option of rm.
Thus I alias rm='rm -i'. But I would not like my scripts to pause, waiting
for my response, every time they remove a file.

If you really want to use aliases in a script, define them in the script.
Alternatively if certain aliases are used by many scripts, but them in a
separate file in your 'lib' directory and source them in with ". ~/lib/myaliases".
.



Relevant Pages

  • Re: [Long] about ksh93 (Was: Bourne Shell Programming on Windows)
    ... :>: Are you saying that David Korn is an unitiated or ignorant ksh ... :> won't be called in a script. ... :> in every shell. ... that should be teached in every shell programming book. ...
    (comp.unix.shell)
  • Re: Ksh and the parent/child relationship - a deep dive
    ... Can someone smarter that me provide an example of a parent ksh script ... korn shell script",DF ... "Unix Review: Shell Corner: Managing Background Commands in Shell ...
    (comp.unix.shell)
  • Re: Secure issues on the usage of exec
    ... :> That is because of IFS processing. ... That's why in ksh, to get a newline, you can always ... That's not the case of every Bourne shell. ... first you have to get a setuid ksh script running. ...
    (comp.unix.shell)
  • Re: nohup and sourcing
    ... I have a script called start.sh which contains ... So your default shell is ksh, but you launch a C shell to run the script? ...
    (comp.unix.shell)
  • Re: nohup and sourcing
    ... I have a script called start.sh which contains ... So your default shell is ksh, but you launch a C shell to run the script? ...
    (comp.unix.shell)