bombless
V2EX  ›  macOS

我新建一个 shell 文件,用 source 执行或者用 zsh/bash 执行都正常,但是直接执行就卡住没有输出,这个问题怎么排查

  •  
  •   bombless · Oct 2, 2021 · 3214 views
    This topic created in 1858 days ago, the information mentioned may be changed or developed.

    比如我 shell 文件是这样,文件名是 test:

    #!/bin/bash
    echo bash test
    

    我zsh test, bash test, source test都正常 但是./test它就直接卡住没有输出

    shell

    这个怎么排查?只能重装系统了吗?

    7 replies  •  2021-10-03 01:13:41 +08:00
    FurN1
    FurN1
    Oct 2, 2021
    1
    which bash 看看输出,然后改你的 shebang line
    或者直接把 shebang ling 改成#!/usr/bin/env bash
    FurN1
    FurN1
    Oct 2, 2021
    2
    你用 mac 的话,用 homebrew 安装的 bash 本来就不在 /bin/bash,应该是 /usr/local/bin/bash 。无论如何,shebang line 换成#!/usr/bin/env bash 都比较方便
    bombless
    bombless
    OP
    Oct 2, 2021
    3
    喔我重启过后就没事了……
    不知道发生了什么

    我用 /bin/bash 是因为 /bin/zsh 和 /bin/bash 本来就是系统预装的位置

    说真的反而是 env 的位置在 mac 和 linux 中不同

    我反而感觉 /bin/sh 稳一点
    sky96111
    sky96111
    Oct 2, 2021 via Android
    4
    @bombless 可以,只要你不用一些 baah 专属语法
    FurN1
    FurN1
    Oct 2, 2021
    5
    @bombless mac 也是有 /usr/bin/env 的,尽管 homebrew 安装 coreutils 之后会带一个 env 。
    billlee
    billlee
    Oct 3, 2021
    6
    @bombless /bin/sh 在 debian 系下可不是 bash
    bao3
    bao3
    Oct 3, 2021 via iPhone
    7
    还是用 sh 吧,标准的 posix,在哪都能用
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2356 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 15:46 · PVG 23:46 · LAX 07:46 · JFK 10:46
    ♥ Do have faith in what you're doing.