如何在Shell脚本中解决此错误:“读取:非法选项-t"? [英] How can I resolve this error in shell scripting: "read: Illegal option -t"?

查看:83
本文介绍了如何在Shell脚本中解决此错误:“读取:非法选项-t"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#!/bin/bash
echo -n "Hurry up and type something! > "
if read -t 10 response ; then
echo "Greate, you made it in time!"
else
echo "sorry, you are too slow!"
fi

我已经在终端中编写了以上代码,并收到错误消息"read:Illegal option -t".

I have written above code in terminal and got error "read: Illegal option -t".

推荐答案

Bash支持 -t ,因此您似乎正在尝试使用 sh 或其他一些外壳,这很奇怪,因为您具有正确的射手.

Bash supports -t, so it looks like you're trying to execute it with sh or some other shell, which is odd, since you have the correct shebang.

确保使用 ./script path_to_script/script 运行它.如果只是在终端中运行,请先启动 bash .

Make sure you run it with ./script or path_to_script/script. If you just run it in the terminal, first start bash.

这篇关于如何在Shell脚本中解决此错误:“读取:非法选项-t"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆