Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have written this simple type alias script in my bin dir in home

#!/bin/sh
alias kp='ls –L'
alias ldir='ls –aF'
alias copy='cp'

and saved it in the name myenv.Then I have changed the mode using

chmod +x /bin/myenv

then execute it using the command

myenv

but after this when I use kp it says kp command not found.Why?

share|improve this question

2 Answers 2

Your script runs in a sub-shell by default. (It opens a new shell and runs your script. After the script has finished running, its modified environment is destroyed.)

If you'd like to change your current shell environment settings you have to:

source myenv

or:

. myenv

See man bash Shell Builtin Commands / Source.

share|improve this answer

First, because character that you used in alias kp='ls –L' and alias ldir='ls –aF' is not the same with - (you can see that is a little bit longer). Try:

#!/bin/sh
alias kp='ls -L'
alias ldir='ls -aF'
alias copy='cp'

Just copy and paste from above.

Second, if you want that the script to have the expected effect, just put this line in ~/.bashrc file:

source /bin/myenv

Anyway, the best way to create aliases in Ubuntu is to use this method: http://askubuntu.com/a/5278/147044.

share|improve this answer
    
Thanks.. But creating alias isnt my goal. I am just learning to create shell scripts –  Tamim Ad Dari Jun 24 '13 at 8:38
    
@TamimAdDari Ok, if the answer was useful, you should accept it. In general you should do this. See What should I do when someone answers my question? and What does it mean when an answer is "accepted"?. –  Radu Rădeanu Jun 24 '13 at 9:19
    
alright.. thanx... –  Tamim Ad Dari Jun 24 '13 at 15:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.