[英]“read” command not popping up an input window (when run without a terminal) in bash
I am having some issues where running a script that I have placed in my file browsers scripts folder making it runnable from the right-click menu, is not capable of actually producing a prompt for user-input when the read command is called.我在运行我放置在文件浏览器脚本文件夹中的脚本使其可从右键单击菜单运行时遇到一些问题,但在调用读取命令时实际上无法生成用户输入提示。
Is there any way to force it to create the prompt?有没有办法强制它创建提示?
This is the code I am using to test it, nothing much:这是我用来测试它的代码,没什么:
#!/bin/bash
read -p "Hour " answer
hours=$answer
My script is being invoked from the right-click menu in Nemo (the file browser in Linux Mint 19.2), being installed in /home/username/.local/share/nemo/scripts
.我的脚本是从 Nemo 的右键菜单调用的(Linux Mint 19.2 中的文件浏览器),安装在/home/username/.local/share/nemo/scripts
中。
read
works fine from a terminal, or running a script with "run in terminal", but the right-click menu in Nemo doesn't start one.从终端read
可以正常工作,或者使用“在终端中运行”运行脚本,但 Nemo 中的右键菜单不会启动。
This was based on a misunderstanding of what the read
command does.这是基于对read
命令作用的误解。 As pointed out by both tripleee and charles duffy, the read command can't actually create its own terminal window.正如triplee 和charles duffy 都指出的那样,读取命令实际上不能创建自己的终端window。 On my OS, Zenity is preinstalled, so the following works correctly as a replacement for read -p 'This is a test! ' myvar
在我的操作系统上,Zenity 是预装的,所以下面的代码可以正确地替代read -p 'This is a test! ' myvar
read -p 'This is a test! ' myvar
: read -p 'This is a test! ' myvar
:
#!/bin/bash
myvar=$(zenity --entry --text="This is a test!")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.