声明-A返回无效选项使用Apple M1上的Bash版本5
我已经阅读了有关Stackoverflow的类似文章,但是没有解决我的特定问题,我真的很感谢任何帮助,因为我真的在这本书上失去了理智。
- 我有一个使用Shebang
#!/usr/bin/env bash
的脚本,我已经使用Echo在脚本内检查了bash的版本,它的确是bash版本5
我通过Homebrew下载的 - 我读到我不需要使用路径/opt/homebrew/bin/bash 它是我的bash所在的位置[苹果M1 CPU] Shebang粘贴在第1点。
- 我的VSC终端正在使用ZSH。
- 由于某种原因,即使
声明-a
应由4后bash版本支持,但我返回以下错误:声明:-a:无效选项声明:用法:声明[-affirtx] [-p] [-p] [name [= value] ...]
- 我的脚本如下:
#!/usr/bin/env bash
echo "BASH_VERSION=$BASH_VERSION"
# save current branches in packages as `composer install` may change them to master
SCRIPTPATH="$( cd "$( /usr/bin/dirname "$0" )" && pwd )"
DIR=`pwd`
declare -A BRANCHES
DIR=`pwd`
for d in */; do
cd "$DIR/$d"
BRANCH=`git rev-parse --abbrev-ref HEAD`
if [ "${BRANCH}" != "master" ]; then
BRANCHES[$d]="${BRANCH}"
fi
done
返回的bash版本:
BASH_VERSION=5.1.16(1)-release
有建议吗?请让我知道您需要哪些其他细节。另外,也许是宣布关联数组的替代语法,也许我在初始化之前无法声明它们?
我也对此有一个问题。该脚本位于Docker目录内 - 如果Docker打算将虚拟Linux用于安装和实例 - 那么为什么我需要对我的Shell脚本进行某些MACOS支持的更改?
I have read similar articles on stackoverflow but none addressing my specific issue, I would really appreciate any help as I am really losing my mind on this one.
- I have a script that is using the shebang
#!/usr/bin/env bash
, I have checked the version of bash inside of the script by using echo and it is indeedbash version 5
that I downloaded via HomeBrew - I read that I do not need to use the path/opt/homebrew/bin/bash
which is where my bash is situated [apple M1 cpu] because of the shebang pasted in point 1. - My vsc terminal is using zsh.
- For some reason even though
declare -A
should be supported by bash versions after 4, I am returned the following error:declare: -A: invalid option declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
- My script is as follows:
#!/usr/bin/env bash
echo "BASH_VERSION=$BASH_VERSION"
# save current branches in packages as `composer install` may change them to master
SCRIPTPATH="$( cd "$( /usr/bin/dirname "$0" )" && pwd )"
DIR=`pwd`
declare -A BRANCHES
DIR=`pwd`
for d in */; do
cd "$DIR/$d"
BRANCH=`git rev-parse --abbrev-ref HEAD`
if [ "${BRANCH}" != "master" ]; then
BRANCHES[$d]="${BRANCH}"
fi
done
Returned bash version:
BASH_VERSION=5.1.16(1)-release
Any advice? Please let me know what other details you require. Also, perhaps an alternative syntax to declaring associative arrays, perhaps I cannot declare them before initializing?
I have a subsequent question regarding this as well. This script sits inside of a docker directory - if docker is meant to use the virtual Linux for installations and instances - why then would I need to make certain macOS supported changes to my shell scripts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能否确保在本地Env-VAR路径中,所需的路径
/opt/homebrew/bin
位于/bin/的前面? Shebang#!/usr/bin/env bash
只要求它通过路径定义的目录进行检查时,将其定位为第一个爆炸。can you ensure that in your local env-var PATH, the desired path
/opt/homebrew/bin
is situated in front of /bin/? The Shebang#!/usr/bin/env bash
simply asks it to locate the first bang executable when it checks through directories defined by PATH.