模拟用户输入以使用不同参数多次调用脚本
我必须使用提供的脚本,该脚本在脚本运行时接受用户输入而不是参数。我无法解决这个问题。
脚本的一个例子是:
#!/bin/bash
echo "param one"
read one
doSomething
echo "param two"
read two
doSomething
echo "param three"
read three
doSomething
echo "param four"
read four
doSomething
echo "param five"
read five
doSomething
我想要一种能够调用此脚本并提供参数化输入的方法,例如:
./scriptNameWrapper.ksh 1 22 333 4444 55555
我尝试过谷歌搜索,要么我没有正确地提出问题,要么更有可能我可以'只见树木,不见森林。
我已经尝试过这个,但不起作用:
#!/bin/bash
./scriptName.ksh
<<$1
<<$2
<<$3
<<$4
<<$5
我显然不是 *nix 专家,但我确信我以前见过这样做,我只是找不到任何例子。这开始变得令人沮丧,任何帮助将不胜感激。
I have to use a provided script that takes user input while the script is running instead of parameters. I can't get around this.
An example of script would be:
#!/bin/bash
echo "param one"
read one
doSomething
echo "param two"
read two
doSomething
echo "param three"
read three
doSomething
echo "param four"
read four
doSomething
echo "param five"
read five
doSomething
I would like a way to be able to call this script and provide parameterized input, something like:
./scriptNameWrapper.ksh 1 22 333 4444 55555
I've tried googling, and either I'm not asking the question correctly, or more likely I can't see the wood for the trees.
I've tried this, which doesn't work:
#!/bin/bash
./scriptName.ksh
<<$1
<<$2
<<$3
<<$4
<<$5
I'm clearly not a *nix expert, but I'm sure I've seen this done before, I just can't find any examples out there. This is beginning to get frustrating, and any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据您的尝试,您可能看到的内容称为 here-document 。
它应该看起来像这样:
What you've probably seen, based on your attempt, is called a here-document.
It should look like this:
像这样调用您的脚本:
每个参数之间的 \n 序列模拟按下的 Enter 键。
Call your script like this:
The \n sequence between each parameter emulates the enter key being pressed.
将参数放入文件中,每行一个,然后运行
Put your paramaters in a file one per line then run