相关疑难解决方法(0)

当“/bin/sh”指向“/b​​in/bash”时运行shell脚本

我在这个问题中阅读了以下内容:

bash 支持 --posix 开关,这使其更符合 POSIX 标准。如果作为 sh 调用,它还会尝试模仿 POSIX 。

上面的引用假定/bin/sh是指向 的链接/bin/bash

但我不太明白“作为 sh 调用”是什么意思。


假设我有以下名为“script.sh”的脚本:

#!/bin/bash
echo "Hello World"
Run Code Online (Sandbox Code Playgroud)

请在以下每种情况下告诉我脚本是在正常bash模式下还是在 POSIX 模式下运行(假设我在正在运行的终端中执行了以下命令bash):

  1. sh script.sh
  2. bash script.sh
  3. ./script.sh

现在说我有以下脚本,称为“script.sh”(类似于上面的脚本,但没有shebang):

echo "Hello World"
Run Code Online (Sandbox Code Playgroud)

请在以下每种情况下告诉我脚本是在正常bash模式下还是在 POSIX 模式下运行(假设我在正在运行的终端中执行了以下命令bash):

  1. sh script2.sh
  2. bash script2.sh
  3. ./script2.sh

linux shell bash

11
推荐指数
2
解决办法
5354
查看次数

标签 统计

bash ×1

linux ×1

shell ×1