开发者

Bash script help with echo and commands

What I'm t开发者_开发知识库rying 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.


Try something like this:

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜