linux - bash - 读取:非法选项 -n

Phi*_*hil 0 linux script shell

在 Ubuntu 上,我尝试暂停bash shell 脚本

!#/bin/bash
...
read -n 1 -p"pause"
Run Code Online (Sandbox Code Playgroud)

我到处都看到这种语法,所以我不明白为什么它不起作用

我收到这个错误

./build.sh: 14: read: Illegal option -n
Run Code Online (Sandbox Code Playgroud)

我也不明白的是,在阅读手册中,没有 -n -p 选项

Linux 中有两种不同的读取命令吗?

纯粹的

xen*_*oid 5

read是一个bash 内置函数,有一个-n选项。

您可能正在运行dash一个更简单的 shell,其中read -n会引发该错误消息。

请注意,您的“shebang”是错误的(!#而不是#!),因此您可能无法按bash预期运行脚本。在 Ubuntu 中,默认 shell(/usr/bin/sh/bin/sh是到dash.