简体   繁体   English

在Solaris Sparc中设置路径

[英]Setting path in Solaris Sparc

I have one python command file, i want to set it as a PATH in Solaris Sparc so that i can easily use my command from anywhere. 我有一个python命令文件,我想在Solaris Sparc中将其设置为PATH,以便可以在任何地方轻松使用命令。 For example the file name is abc.py and it contains abc --version to display version of file abc. 例如,文件名是abc.py,它包含abc --version以显示文件abc的版本。 So, after opening terminal i should only give command abc --version and it should display version of abc. 因此,在打开终端后,我应该只给出命令abc --version,它应该显示abc的版本。

The architecture (SPARC) has nothing to do with the PATH which is more a shell thing but you do not tell what shell you are using. 架构(SPARC)与PATH无关,它更像是外壳程序,但您不知道使用的是哪个外壳程序。

Anyway, if you use a bourne style shell, ie not csh/tcsh , and you don't mind this to affect every user account on that host, you might add the wanted path to the PATH setting in the file /etc/profile . 无论如何,如果使用bourne样式的shell,即不使用csh/tcsh ,并且您不介意这会影响该主机上的每个用户帐户,则可以在/etc/profile文件中的PATH设置中添加所需的路径。

When abc.py is located in your homedir, you can start it with ~/abc.py . 当abc.py位于您的homedir中时,您可以使用~/abc.py来启动它。 You need to call the file abc.py with abc.py , not abc (and have a shebang line which instructs the shell where it can find python). 您需要使用abc.py而不是abc来调用文件abc.py(并有一个shebang行,该行指示shell可以在其中找到python)。
When you want to start the file with ./abc, you can rename the file to abc (the shebang will tell it is python, not the .py ), or introduce an alias: 当您想以./abc开始文件时,您可以将文件重命名为abc(shebang会告诉它是python,而不是.py ),或引入别名:

alias abc="~/abc.py"

Using an alias can be an alternative for adding a shebang line: 使用别名可以替代添加shebang行:

alias abc="/usr/bin/python abc.py"

When you do not want to use an alias you can make a bin dir and put abc there. 当您不想使用别名时,可以创建一个bin目录并将abc放在其中。
I will add the shebang for you: 我将为您添加shebang:

mkdir ~/bin
echo "#!/usr/bin/python" > ~/bin/abc
cat abc.py >> ~/bin/abc
chmod +x ~/bin/abc
mv abc.py bin/abc.py.old

Now change your login PATH with PATH=${PATH}:$HOME/bin in your .profile or .bashrc , and login again (or source the login script). 现在改变你的登录路径PATH=${PATH}:$HOME/bin在你.profile.bashrc ,并重新登录(或source登录脚本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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