如何防止用户在读取-n命令期间将文件拖入文件中

 收藏

I have a bash script that asks the user for single-key inputs to select from some menu screens. I'm using read -n 1 -s -r -p '' and then doing stuff based on the user input passed through a small set of if statements.

I need to be able to prevent the user from accidentally dragging in a file acting as an input to the read command. I'm very open to replacing the read command to then allow me to prevent this user action from disrupting the process, but I need this to be compatible with most shells.

现在,正如人们所期望的,拖入文件会在终端中输入文件路径,因此外壳程序将其视为用户实际按下了键。

我不希望用户能够使用复制/粘贴或拖动文件作为响应读取提示的方式。

这可能吗?我不介意它是否复杂并且可能不值得。我肯定会实现它:D

回复