当bash执行某个程序时,它只从PATH中去找,如果这个程序不在PATH中,则需要给出具体路径,./run.sh前面的点即表示当前目录。


bash调用程序的几种形式:

1. 在PATH中,直接调用:run.sh

2. 不在PATH,给出完整路径:/tmp/run.sh

3. 不在PATH,给出相对路径:./run.sh

4. 不在PATH,将程序作为参数传给bash:sh run.sh


[root@rhel6-server tmp]# pwd
/tmp
[root@rhel6-server tmp]# cat run.sh

echo "hello world!"
[root@rhel6-server tmp]# ll
total 4
-rwxr-xr-x. 1 root root 20 Feb 28 00:20 run.sh
[root@rhel6-server tmp]# env | grep PATH
PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@rhel6-server tmp]# run.sh
-bash: run.sh: command not found
[root@rhel6-server tmp]# /tmp/run.sh
hello world!
[root@rhel6-server tmp]# ./run.sh
hello world!
[root@rhel6-server tmp]# sh run.sh
hello world!
[root@rhel6-server tmp]# PATH=.:$PATH
[root@rhel6-server tmp]# env | grep PATH
PATH=.:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@rhel6-server tmp]# run.sh
hello world!
[root@rhel6-server tmp]#



REF:http://linux.vbird.org/linux_basic/0210filepermission.php#dir_path

相关文章:

  • 2021-12-26
  • 2022-12-23
  • 2022-02-01
  • 2022-12-23
  • 2021-12-04
  • 2021-11-20
  • 2021-11-03
猜你喜欢
  • 2022-12-23
  • 2021-04-24
  • 2022-01-22
  • 2022-12-23
  • 2021-10-04
  • 2021-11-14
  • 2021-09-24
相关资源
相似解决方案