On Fri, Apr 10, 2015 at 01:05:13PM +0200, Benny Lofgren wrote:
> On 2015-04-10 04:21, Henrique Lengler wrote:
> > Very strange.
> > I can manually set a alias running:
> > 
> > alias clr=clear
> > # an then run the clr command will work.
> > 
> > But If I try running the .kshrc file it don't work:
> > 
> > /home/henri $ ./.kshrc
> > /home/henri $ clr
> > /bin/ksh: clr: not found
> > 
> > /home/henri $ sh .kshrc
> > /home/henri $ clr
> > /bin/ksh: clr: not found
> 
> Why this doesn't work is because when you execute a script like above
> what the shell does is start a new shell, run the script in that shell
> and wait for it to exit before you get the next prompt.
> 
> What that means is that the *new* shell sets your aliases, shell
> variables and funtions, but they are then forgotten again when that
> shell exits. Your actual command shell never gets to see what is done.
> 
> If you on the other hand execute the script the way patrick keshishian
> suggests in his mail (*), a process normally called "sourcing the
> script", it runs in the same shell that you give commands to, just as if
> you had entered the script by hand with your keyboard.
> 
> And then it will Just Work <tm>. :-)
> 
> 
> (*) Like this:
> 
>   $ . ~/.kshrc

Ok, so executing it like this makes it work.

I puted some checks after each line, like this:

----
export PS1='$PWD $ '
echo ALIAS 1
alias ls='ls -p'

alias clr
alias clr=clear
alias clr

alias p='ps -l'
alias df='df -h'
------

And I receive this:
-----------
/home/henri $ . ~/.kshrc
ALIAS 1
clr alias not found
clr=clear
------

So the problem is to make this work under X. The alias are working out
of X and in X if applied by hand.

> From your questions I'm deducing that you are not very familiar with how
> the shell really works, especially when it comes to the interaction
> between unix processes. This is very useful knowledge!
> 
> The best source for information is always the man page!
> 
> ksh's man page is very big and probably intimidating at first, but I
> really, really recommend that you do "man ksh" and read  it!
> 
> It contains the answer to most of your problems, and a good
> understanding of how the shell works is essential for any budding unix
> hacker. :-)

I will read it.

-- 
Regards

Henrique Lengler 

Reply via email to