Bash 脚本帮助显示 echo 和命令

发布于 2024-11-06 21:45:48 字数 323 浏览 0 评论 0原文

我想做的是让这个脚本读取用户输入,然后使用用户输入执行命令。我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笛声青案梦长安 2024-11-13 21:45:48

尝试这样的事情:

gnome-terminal -t 'Change User Password' -x bash -c "echo 'What user needs their
 password change?' ; read pswu ; passwd \$pswu "

Try something like this:

gnome-terminal -t 'Change User Password' -x bash -c "echo 'What user needs their
 password change?' ; read pswu ; passwd \$pswu "
梦里寻她 2024-11-13 21:45:48

我认为您尝试使用错误的工具来完成这项工作,主要是因为 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 as passwd 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 the bash-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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文