Bash 脚本帮助显示 echo 和命令
我想做的是让这个脚本读取用户输入,然后使用用户输入执行命令。我的 echo 工作正常,但之后我无法让其余部分工作。
gnome-terminal -t 'Change User Password' \
-x bash -c "echo 'What user needs their password change?' ; bash" \
-x bash -c "read pswu ; bash" \
-x bash -c "passwd $pswu ; bash"
另一个问题:我想知道如何右键单击文件并运行文件名不带路径或扩展名的脚本。
What I'm trying to do is to make this script read a users input and them perform the command with the users input. I got echo working, but I can't get the rest to work after.
gnome-terminal -t 'Change User Password' \
-x bash -c "echo 'What user needs their password change?' ; bash" \
-x bash -c "read pswu ; bash" \
-x bash -c "passwd $pswu ; bash"
Another question: I would like to know how to right-click a file and run a script with the filename without path or extension.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的事情:
Try something like this:
我认为您尝试使用错误的工具来完成这项工作,主要是因为
passwd
不读取标准输入,而是从终端(/dev/tty)读取。您可能需要使用
expect
或其之一各种类似的工作。这是为了驱动诸如passwd
之类的程序而设计的,这些程序是交互式的并且需要终端输入(而不是标准输入)。看看所提出的三重命令,我不明白第三个
-x bash
将如何从第二个命令获取信息。我也不清楚脚本内的 bash 正在做什么。当然,您会编写一个完成整个工作的脚本,然后调用终端来运行该脚本。在我看来,运行这样的三个命令是非常有问题的。I think you are trying to use the wrong tool for the job, mainly because
passwd
doesn't read form standard input but from the terminal (/dev/tty).You probably need to use
expect
or one of its various workalikes. This is designed to drive programs such aspasswd
which are interactive and expect terminal input (rather than standard input).Looking at the triple-command being proposed, I do not see how the third
-x bash
is going to get the information from the second. I'm not clear what thebash
-inside-the-script is doing, either. Surely, you would write a script which does the entire job, and then invoke the terminal to run that script. Running three commands like that is very problematic, it seems to me.