简体   繁体   English

“读取”命令未在 bash 中弹出输入 window(无终端运行时)

[英]“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.

相关问题 Mono:如何在新的控制台/终端窗口上运行 bash 命令? - Mono: how to run a bash command on a new console/terminal window? 在启动git bash终端之前如何运行linux命令 - How to run linux command before starting up git bash terminal 在bash脚本中读取命令而不是在管道传输到bash时等待用户输入? - Read command in bash script not waiting for user input when piped to bash? 读命令没有从终端输入 - read command is not taking input from the terminal 在没有python命令的情况下在终端中运行python脚本 - run a python script in terminal without the python command 当只有`read(2)`出现在Bash中的`whatis`时,如何看到`read`命令的手册页? - How to see man page of `read` command when only `read(2)` shows up by `whatis` in Bash? 在当前终端中执行命令,而无需打开新终端。 - Execute command in current terminal, without opening up a new terminal. 关闭终端窗口后如何运行特定的bash shell脚本? - How to run a particular bash shell script after closing a terminal window? Bash是默认设置,但是当我在终端中运行“ bash:”时仍会更改 - Bash is default, yet still changes when I run "bash: in terminal? Bash 脚本如何远程运行命令然后退出远程终端 - Bash script how to run a command remotely and then exit the remote terminal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM