gpt4 book ai didi

linux - 来源与执行脚本 : in which shell process do they run?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:31:20 26 4
gpt4 key购买 nike

这一切都在 ubuntu 中使用终端。

在首次创建文件后获取文件时,您是否需要先获得read 权限?

然后执行你需要executable权限所以它会显示x when使用 ls -l 文件名?

我不确定是什么进程在您获取源代码时执行内容?它会是 current shell 吗?

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

开始学习Linux,尝试了解脚本的权限和流程。

最佳答案

做个小实验;

$ 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!

关于linux - 来源与执行脚本 : in which shell process do they run?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58121899/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com