bash的用户输入,如果 [英] bash user input if

查看:113
本文介绍了bash的用户输入,如果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我特林做简单

Do you want to do that? [Y,n] _

在bash的问题。

question in bash.

我试图

echo "Do that? [Y,n]"
read DO_THAT
if ["DO_THAT"="y"]; then
  do_that
fi

但它失败:庆典:Y = Y]:命令未找到

我在做什么错?!

推荐答案

您可以考虑明确提示:-p并指定1个字符的输入-n1它允许插入Ÿ无ENTER

You might consider explicit prompting: -p and specifying 1-character-input -n1 which allows to insert y without ENTER.

read -n1 -p "Do that? [y,n]" doit 
case $doit in  
  y|Y) echo yes ;; 
  n|N) echo no ;; 
  *) echo dont know ;; 
esac

这篇关于bash的用户输入,如果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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