QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1509|回复: 10

关于运行shell程序的问题

[复制链接]
发表于 2006-6-16 09:17:15 | 显示全部楼层 |阅读模式
我写了一个shell程序,名叫“test.sh”,我运行的时候输入“./test.sh”提示没有权限,但是如果输入“. test.sh”就能够正常运行,这是为什么?这两种运行方式有什么不同?
谢谢
发表于 2006-6-16 10:18:34 | 显示全部楼层
./test.sh 必须是可执行的才可以。
. test.sh 相当于
source test.sh 不需要该文件具有可执行权限。
回复

使用道具 举报

 楼主| 发表于 2006-6-16 10:21:43 | 显示全部楼层
他们两个有什么本质区别吗?
回复

使用道具 举报

发表于 2006-6-17 00:54:17 | 显示全部楼层
父shell,子shell
回复

使用道具 举报

 楼主| 发表于 2006-6-17 08:17:10 | 显示全部楼层
./ 是父shell
.  是子shell
对吗?
那为什么在父shell中要具有可执行权限才行?
回复

使用道具 举报

发表于 2006-6-17 11:11:53 | 显示全部楼层
与父子shell无关!

解释一下 . 和./区别

source filename [arguments]

              Read and execute commands from filename in the current shell environment and return
              the exit status of the last command  executed from filename.  If filename  does  not
              contain a slash, file names in PATH are used to find the directory containing file-
              name.  The file searched for in PATH need not be executed .  When bash is  not  in
              posix  mode, the current directory is searched if no file is found in PATH.  If the
              sourcepath option to the shopt builtin command is  turned  off,  the  PATH  is  not
              searched.   If  any  arguments  are supplied, they become the positional parameters
              when filename is executed.  Otherwise the positional parameters are unchanged.  The
              return  status  is the status of the last command exited within the script (0 if no
              commands are executed), and false if filename is not found or cannot be read.
回复

使用道具 举报

 楼主| 发表于 2006-6-17 20:52:59 | 显示全部楼层
你们的解释到底谁对呀?有人说是父shell和子shell,有人说是source?
回复

使用道具 举报

发表于 2006-6-17 21:17:11 | 显示全部楼层
. 就是source
再看上面的解释。。 上面说的很详细!
不明白?》?!?!?!
回复

使用道具 举报

 楼主| 发表于 2006-6-17 21:53:10 | 显示全部楼层
" file names in PATH are used to find the directory containing file-
name."这句是什么意思?
PATH是环境变量吧,那么在PATH中的文件名怎么样?
回复

使用道具 举报

发表于 2006-6-17 22:19:34 | 显示全部楼层
Sorry, . means "source".
BOoRFGOnZ was right!
回复

使用道具 举报

发表于 2006-6-20 12:17:40 | 显示全部楼层
难得zhy2111314夸我一句  
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-9-30 08:12 , Processed in 0.061619 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表