我在有一个shell脚本 /home/joey/hello.sh
现在,我想喜欢的任何地方执行它pwd
,cut
,sort
,grep
。
因此,hello.sh
尽管我在另一个目录中,但我只是键入。
要执行脚本,您应该使其可执行。
chmod u+x /home/joey/hello.sh
在您可以执行之后
./hello.sh # if you are in the same directory
~/hello.sh # if you are in another directory
hello.sh # if you put in a directory included in the $PATH
与echo $PATH
您一起可以看到路径中包含的所有目录,选择一个您可以在其中写入(通常为~/bin
)的目录,mv
然后在其中
mv ~/hello.sh ~/bin # If /home/bin is in your path
笔记
~
是表示您的主目录(/home/joey
)的一种简短方法本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句