模拟用户输入以使用不同的参数多次调用脚本 [英] Simulate User Input To Call Script Multiple Times With Different Parameters

查看:69
本文介绍了模拟用户输入以使用不同的参数多次调用脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用提供的脚本来在脚本运行时接受用户输入,而不是使用参数.我无法解决这个问题.

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.

脚本的示例为:

#!/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

我显然不是* nix专家,但是我敢肯定我以前看过这件事,我只是找不到任何例子.这开始令人沮丧,任何帮助将不胜感激.

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.

推荐答案

根据您的尝试,您可能看到的内容称为

What you've probably seen, based on your attempt, is called a here-document.

它应该看起来像这样:

#!/bin/bash

./scriptName.ksh <<-END_PARAMS
    $1
    $2
    $3
    $4
    $5
END_PARAMS

这篇关于模拟用户输入以使用不同的参数多次调用脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆