gpt4 book ai didi

bash - 子shell中使用的"basename"返回"command not found"

转载 作者:行者123 更新时间:2023-12-04 02:53:34 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Find "command not found" when executed in bash loop

(1 个回答)


2年前关闭。




运行此脚本时:

#!/bin/sh -ex

if [[ $# -ne 1 ]]; then
echo "./import-public-ssh-key.sh <absolute path to public key>"
exit 1;
fi

PATH=$1
KEY=$(basename ${PATH})

我得到:
./import-public-ssh-key.sh: line 9: basename: command not found

没有子 shell basename作品:
$ basename /Users/mles/.ssh/id_rsa.pub
id_rsa.pub

为什么是 basename不在子shell中工作?如果这是相关的,我在 mac 上。

最佳答案

您重置了 PATH。不要那样做。 shell 搜索 PATH 中列出的所有目录,并且您已对其进行了更改,以便 PATH 不再包含包含 basename 的目录。

关于bash - 子shell中使用的"basename"返回"command not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53971379/

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