在bash脚本中建议用户输入的答案 [英] Suggest answer to user input in bash scripting
本文介绍了在bash脚本中建议用户输入的答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是一个例子:
#!/bin/bash
echo -e "Enter IP address: \c"
read
echo $REPLY
但是我想让用户更容易回答.我想向用户提供答案.它应该看起来像这样:
But I want to make it easier for the user to answer. I'd like to offer an answer to the user. It should look something like this:
输入您的IP:192.168.0.4
Enter your IP: 192.168.0.4
用户可以直接按Enter键并同意192.168.0.4,或者删除一些字符(例如,删除带有一个退格键的"4",然后键入3).
And the user can just press Enter and agree with 192.168.0.4, or can delete some characters (for example delete "4" with one backspace and type 3 instead).
如何进行这样的输入?bash有可能吗?
How to make such an input? It is possible in bash?
推荐答案
bash的读取具有readline支持(Jonathan Leffler建议也将提示也置于读取状态)
bash's read has readline support ( Jonathan Leffler suggests to put the prompt into read as well)
#!/bin/bash
read -p "Enter IP address: " -e -i 192.168.0.4 IP
echo $IP
这篇关于在bash脚本中建议用户输入的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文