简体   繁体   中英

alias giving: ~/.bash_profile: No such file or directory

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM