Debian系统中执行shell报错unexpected operator
新的Jenkins测试环境通过docker搭建,官方镜像的基础镜像使用的是Debian系统,在执行到一些shell步骤的时候,总是会报如下错误:
/var/jenkins_home/workspace/ops/test-eryajf-blog@tmp/durable-8207aae1/script.sh: 5: [: ALL: unexpected operator
1
这是由于Debian系统以及Ubuntu系统在最近新系统中,默认的sh软链到的是dash,而非bash。
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Mar 28 08:00 /bin/sh -> dash
1
2
2
通过执行如下命令,可以将sh软链到bash上。
$ dpkg-reconfigure dash
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
Configuring dash
----------------
The system shell is the default command interpreter for shell scripts.
Using dash as the system shell will improve the system's overall performance. It does not alter the shell presented to interactive users.
Use dash as the default system shell (/bin/sh)? [yes/no] no 需在此处输入no
Removing 'diversion of /bin/sh to /bin/sh.distrib by dash'
Adding 'diversion of /bin/sh to /bin/sh.distrib by bash'
Removing 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by dash'
Adding 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by bash'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
更改成功之后,再看一下当前sh的软链:
ls -l /bin/sh
lrwxrwxrwx 1 root root 4 May 21 22:35 /bin/sh -> bash
1
2
2
然后再运行脚本就不会报刚刚那个错了。
上次更新: 2024/02/28, 13:00:35