首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >源脚本与执行脚本:它们在哪个shell进程中运行?

源脚本与执行脚本:它们在哪个shell进程中运行?
EN

Stack Overflow用户
提问于 2019-09-27 01:27:07
回答 1查看 91关注 0票数 1

这一切都是在ubuntu中使用终端实现的。

在第一次创建文件之后采购文件时,您首先需要read权限吗?

然后,您需要executable权限才能执行,以便在使用ls -l filename时显示x

我不确定的是,当你源码的时候,哪个进程会执行这些内容?会是current shell吗?

那么,当您执行调用文件名的脚本时,您将使用new shell进程吗?

开始学习Linux,所以试图理解脚本的权限和进程。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-27 02:14:35

做一个小实验;

代码语言:javascript
复制
$ echo $$ # print PID of current shell
1234
$ echo 'echo $$' > test.sh # make a little shell script that just prints its PID
$ ls -l test.sh
-rw-rw-r-- 1 hlub hlub 10 Sep 26 20:01 test.sh
# no x'es: not executable
$ source test.sh # source it....
1234
# OK, that worked, even without execute permission, 
# .... and we get the same PID: 
# .... apparently "source" runs commands in the current shell
$ ./test.sh
zsh: permission denied: ./test.sh
# Oops! need execute permission
$ chmod a+x test.sh # make the script executable
$ ls -l test.sh
-rwxrwxr-x 1 hlub hlub 10 Sep 26 20:02 test.sh
# x'es, just as I expected!
$ ./test.sh
5678
# OK, so now the script executes in a new process!
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58121899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档