Unix Shell - Executing an alias inside a scritps

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > August 2006 > Executing an alias inside a scritps





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Executing an alias inside a scritps
gfiuni2@gmail.com

2006-08-30, 7:33 am


Hi,

I have defined some alias in ".kshrc" file, but when I execute a script
I can't see them.

How can I see the alias inside a scripts?

Thanks in advance,
Jose Luis.

Radoulov, Dimitre

2006-08-30, 7:33 am

> I have defined some alias in ".kshrc" file, but when I execute a script
> I can't see them.
>
> How can I see the alias inside a scripts?


By executing the script in the current shell with . script (not script or
../script).


Regards
Dimitre



gfiuni2@gmail.com

2006-08-30, 7:33 am


I need run the script with "nohup". How can I do it?

Regards,
Jose Luis.

Radoulov, Dimitre wrote:
>
> By executing the script in the current shell with . script (not script or
> ./script).
>
>
> Regards
> Dimitre


gfiuni2@gmail.com

2006-08-30, 7:33 am


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?

Regards,
Jose Luis.


gfiuni2@gmail.com wrote:
> Hi,
>
> I have defined some alias in ".kshrc" file, but when I execute a script
> I can't see them.
>
> How can I see the alias inside a scripts?
>
> Thanks in advance,
> Jose Luis.


Barry Margolin

2006-08-30, 7:33 am

In article <1156936740.649889.96490@h48g2000cwc.googlegroups.com>,
gfiuni2@gmail.com 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.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Jon LaBadie

2006-08-30, 1:32 pm

Barry Margolin wrote:
> In article <1156936740.649889.96490@h48g2000cwc.googlegroups.com>,
> gfiuni2@gmail.com wrote:
>
>
> 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".
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com