【发布时间】:2019-10-25 16:25:54
【问题描述】:
运行此 sh 脚本时,我收到“Illegal option -n”和“[[: not found”。
该脚本过去可以正常运行很长时间,然后在我在 Ubuntu 18.04.3 VPS 上更新某些内容时开始出现问题。
read -p "Do you wish to enable SSL for this domain? [Y/n]" -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]
then
# something here
else
# something else here
fi
“Illegal option -n”与#1行有关
"[[: not found" 部分与第 3 行有关
【问题讨论】:
-
[[是 ksh 和 bash 扩展。sh不支持。 -
我猜你曾经运行一个古老的 Ubuntu 版本,
/bin/sh由 bash 提供,然后升级到现代版本,它由 dash 提供。任何使用 bash 扩展的脚本都应始终以#!/bin/bash、#!/usr/bin/env bash或类似名称开头 -- not#!/bin/sh-- 或以bash foo调用,而不是sh foo。 -
read -n是另一个仅限 bash 的功能;如果需要,您需要使用 bash,而不是sh。
标签: bash sh ubuntu-18.04