Reputation: 785
I have this script called menal
in my ~/bin
directory:
#!/bin/sh
alias mendir='cd ~/projects/myproject'
It has executable property and I expect that when I run it it sets an appropiate alias for cd
command for the terminal session. But it doesn't. When I type $ menal
in terminal it shows no error, but when I try $ mendir
after that I get
No command 'mendir' found, did you mean:
Command 'menhir' from package 'menhir' (universe)
mendir: command not found
When I type
$ alias mendir='cd ~/projects/myproject'
$ mendir
in terminal, it works.
What am I doing wrong? Is it a script scope issue or something?
Upvotes: 0
Views: 560
Reputation: 29635
You can add it to your .bash_profile
.
alias mendir='cd ~/projects/myproject'
then do source ~/.bash_profile
It should create the alias and also will work on every login.
Upvotes: 1
Reputation: 2464
Yes, it's a scope problem. Calling it the following way won't produce the result you expect:
./bin/menal
If you want the alias to persist, use source
:
source ./bin/menal
Upvotes: 1