Reputation: 59228
I'm trying to create an alias for reloading my bash profile.
I added the following line into my ~/.bash_profile
alias src='CMD="source ~/.bash_profile"; echo $CMD;$CMD;'
When I try it(I manually run the command first, so now alias src
is defined), it doesn't work:
$ src
source ~/.bash_profile
-bash: ~/.bash_profile: No such file or directory
(Yes, the file is really there) I have similar aliases for other commands they all work. Only this one is causing a problem. Any idea how can I fix this?
Upvotes: 0
Views: 2874
Reputation: 17100
This is because there is no file called ~/.bash_profile
, or, specifically, a directory called ~/
. Bash expands ~
into full path (/home/user/, for example). However, it does not expand after substituting the $CMD
variable.
Try using the full path. Or adding this:
FILE="~/.bash_profile" ; eval FILE=$FILE
FILE will have now the full substituted path.
Upvotes: 2