Showing results for 
Search instead for 
Did you mean: 

simple script is failing

Go to solution
Trusted Contributor

simple script is failing

Hi All,

I was running the below script and somehow it dosent work:-

echo "hello world"
alias 'ps=ps -aef'
alias -x 'bmw=ls -rt'

hello world
Globe1> bmw
ksh: bmw: not found

Plz advice

Honored Contributor

Re: simple script is failing

The aliases only exist inside your script. Once the script ends so do the aliases. Better off putting them in your .profile, .login etc. as appropriate.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
James R. Ferguson
Acclaimed Contributor

Re: simple script is failing


When you ran as:

# ./ executed in your own environment. A child process cannot propagate variables to its pareent.

Instead, do:

# . ./

...and then you can use the 'bmw' alias.


Trusted Contributor

Re: simple script is failing

I do not have write permissions on the .profile and .login...

I type alias after running the script

and my alias dosent work...

Plz help me with a small example

thank you
Paul McCleary
Honored Contributor

Re: simple script is failing


I see you are trying to use:

alias -x

I guess with the aim that the alias is propagated to another shell.

This won't work as you've seen. See this part of ksh man page:

Exported aliases remain in effect for subshells but must be
reinitialized for separate invocations of the shell (see Invoking ksh

You would probably be better just sourcing in a file to set them for each new shell:

. /file

HTH, Paul
Trusted Contributor

Re: simple script is failing

Thanks JRF... It worked

I have learnt something now
Honored Contributor

Re: simple script is failing

If you can write to your home directory, you can always fix the permissions of any files in it, even if you don't have the ownership of the file.

Just copy the original to a new name (you will own the new copy)...

cp .profile

... delete the original...

rm .profile

... and rename the copy you made back to original name.

mv .profile

If the permissions of the file are -r--r--r-- but you are the owner of the file, there is no need to do any copying. You can simply give yourself the write permission:

chmod u+w .profile