[英]How can I add a directory to my $PATH variable so that I may run scripts in bash without typing out the entire file path?
I want to run a bash script "hello.sh" from the command line using only the file name and extension. 我想仅使用文件名和扩展名从命令行运行bash脚本“ hello.sh”。 I added the directory where this file exists ("/Users/myusername/dev"), into the $PATH variable by editing the .bash_profile file.
通过编辑.bash_profile文件,我将该文件所在的目录(“ / Users / myusername / dev”)添加到$ PATH变量中。 However, when I try to run the script, I get "command not found".
但是,当我尝试运行脚本时,出现“找不到命令”。 I am working on MacOSX.
我正在MacOSX上工作。
Here is my $PATH variable, verified from the Terminal app: “/Users/myusername/dev:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin” 这是我的$ PATH变量,已通过终端应用验证:“ / Users / myusername / dev:/Library/Frameworks/Python.framework/Versions/3.4/bin:/ usr / local / bin:/ usr / bin:/ bin :/ usr / sbin:/ sbin”
If I move the script into the /usr/local/bin folder, also in my $PATH, the script can be run by typing it directly. 如果将脚本移到$ usr的/ usr / local / bin文件夹中,也可以直接键入脚本来运行该脚本。 One thought I have is that there might be some user rights I need to set for the directory?
我有一种想法是可能需要为目录设置一些用户权限? Otherwise, did I not set the path correctly within $PATH?
否则,是否没有在$ PATH中正确设置路径?
Two possibilities: 两种可能性:
.bash_profile
is read for login-shells. .bash_profile
作为登录外壳。 You may have overlooked either sourcing the file, eg, . ~/.bash_profile
. ~/.bash_profile
. ~/.bash_profile
or logging out/in. . ~/.bash_profile
或注销/登录。 To check typos, I use a script that shows my path in readable form (see link ). 为了检查错别字,我使用了一个脚本,该脚本以可读的形式显示了我的路径(请参阅链接 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.