[英]Bash no such file or directory every time I open the Ubuntu terminal
I am new to Ubuntu and Linux terminal, for other purposes I have executed some commands related to adding environment variables(I guess) as follows:我是 Ubuntu 和 Linux 终端的新手,出于其他目的,我执行了一些与添加环境变量相关的命令(我猜)如下:
echo "source ~[some path]/setup.bash" >> ~/.bashrc
and和
source ~/.bashrc
However, during my process of figuring out the right path, I executed the above commands with the wrong path several times before I got it right.但是,在我找出正确路径的过程中,我多次使用错误的路径执行上述命令,然后才正确。 Now I think my desired environment variable have been successfully added but those "bad" path have been added and every time I open the terminal I got all those 'bash: xxxx No such file or directory' warning: screen shot It's not a serious bug but I wonder if there is a way I can get rid of them?现在我认为我想要的环境变量已成功添加,但那些“坏”路径已添加,每次打开终端时,我都会收到所有那些“bash:xxxx 没有此类文件或目录”警告:屏幕截图这不是一个严重的错误但我想知道是否有办法摆脱它们? Many thanks!非常感谢!
You've obscured the paths themselves, but I managed to work out that the last file you're trying to load is in the path ~Desktop
, whereas I think you meant ~/Desktop
.您自己掩盖了路径,但我设法弄清楚您要加载的最后一个文件位于路径~Desktop
中,而我认为您的意思是~/Desktop
。 In your .profile
or .bashrc
files, I'd rather use the env variables, though, and use $HOME
for paths under my home directory.不过,在您的.profile
或.bashrc
文件中,我宁愿使用环境变量,并将$HOME
用于我的主目录下的路径。
Lastly, using source
is absolutely fine (and POSIX compliant), but seeing as your file is called .bashrc
, it's safe to assume that you're only targetting bash.最后,使用source
绝对没问题(并且符合 POSIX),但是看到您的文件名为.bashrc
,可以安全地假设您只针对 bash。 To save some typing, bash has source
aliased to .
为了节省一些输入,bash 将source
别名为.
(dot). (点)。 What I'd write in my bashrc file, then, would be:那么,我在我的 bashrc 文件中写的是:
. "${HOME}/Desktop/path/to/script.sh"
This does mean the append echo command you have is probably best changed to use single quotes:这确实意味着您拥有的 append echo 命令可能最好改为使用单引号:
echo '. "${HOME}/some/path/setup.sh"'
Just keep in mind: having multiple slashes where you only need one (eg /home/foo///bar////path///file.sh
) is safer/better than omitting a required slash (which is what was causing your problem).请记住:在只需要一个斜杠的地方使用多个斜杠(例如/home/foo///bar////path///file.sh
)比省略所需的斜杠(这是导致的原因)更安全/更好你的问题)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.