V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
bombless
V2EX  ›  macOS

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

  •  
  •   bombless · Oct 2, 2021 · 2800 views
    This topic created in 1672 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
        1
    FurN1  
       Oct 2, 2021
    which bash 看看输出,然后改你的 shebang line
    或者直接把 shebang ling 改成#!/usr/bin/env bash
    FurN1
        2
    FurN1  
       Oct 2, 2021
    你用 mac 的话,用 homebrew 安装的 bash 本来就不在 /bin/bash,应该是 /usr/local/bin/bash 。无论如何,shebang line 换成#!/usr/bin/env bash 都比较方便
    bombless
        3
    bombless  
    OP
       Oct 2, 2021
    喔我重启过后就没事了……
    不知道发生了什么

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

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

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