MacOS Bash转zsh 错误汇总

MacOS Bash转zsh 错误汇总

0x0:

Error:declare: usage: declare [-afFirtx] [-p] [name[=value] ...]

// update Bash3.2 to Bash 5.0+

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
brew install bash
brew upgrade bash

#设置默认shell
chsh -s /usr/local/bin/bash

#升级系统bash
// sudo rm /bin/bash
sudo mv /bin/bash /bin/bash.bak
sudo ln -s /usr/local/bin/bash /bin/bash


// out :ln: /bin/bash: Operation not permitted
# 需要关闭系统[SIP](https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/Introduction/Introduction.html)

进入系统Recovery模式 ,重启cmd+R进入:

csrutil disable
csrutil enable

// mv: rename /bin/bash to /bin/bash.bak: Read-only file system
// ln: /bin/bash: File exists
# 第一步
//先检查
csrutil status
// System Integrity Protection status: disabled.
# 第二步
sudo mount -uw /

for Jenkins:

  • 给jenkins设置shell 路径 ,这里需要给系统用户操作jenkins目录的权限
  • 还是升级系统bash划算

0x1:

Error:zsh: bad set of key/value pairs for associative array
1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
zsh --version 
// out: zsh 5.7.1
// 错误提要 localdeclare 报相同错误
// declare bash 4.0以上才支持
TAGS='a 1 b 2 c 3'
local -A tag=($TAGS)
// out :zsh: bad set of key/value pairs for associative array

//该问题为zsh的bug
// 需要将zsh改为5.8+
brew install zsh
brew upgrade zsh
source ~/.zshrc
// 如果为更新成功 需要运行如下语句
// echo 'export PATH="/usr/local/opt/ncurses/bin:$PATH"' >> ~/.zshrc

//更改为
local -A tag=($(echo $TAGS))

//declare取值不需要 declare -x version=${tag[a]}
NS='a'
// 改为直接取值
version =${tag[${NS}]}.${BUILD_NUMBER}