You are not logged in.
Pages: 1
...ok, maybe my subject wasn't too good, but say I have two files
blah.sh and another random program that runs blah.sh
blah.sh
----------
#! /bin/bash
read $1
print $1
----------
(or something like that)
and the other program to run 'blah.sh' and then input (while running) the program something for blah.sh to read?
Offline
#!/bin/bash
#main.sh
#[...]
user_input=$(blah.sh) #I'm assuming "blah.sh" has +x.
#[...]
#!/bin/bash
#blah.sh
read user_input
echo "$user_input"
Last edited by Wintervenom (2009-09-05 18:33:38)
Offline
If you mean you want blah.sh to read input from the user and return it to your main script, Wintervenom's suggestion is good. If you want to pass input to blah.sh from inside your script (so you edit it in your main script and it shows on blah.sh's stdin), use:
/path/to/blah.sh <<EOF
This is input that will be passed to blah.sh.
Everything up to the EOF is captured and passed to the script.
EOF
Offline
erm...
like
there is
"blah.sh" and "main.sh"
main.sh has some things to pass to blah.sh
./main.sh
would then run ./blah.sh or whatever, and then input, for example "123" (without the user running the program to input it)
and then blah.sh would output 123
Offline
Maybe you mean something like this?
main.sh
blah.sh Hello World
blah.sh
echo $*
Offline
...ok, maybe my subject wasn't too good
Yeah, not so good. Please use descriptive thread titles so that others may be able to benefit from this thread.
Offline
Instead of using examples like blah.sh and main.sh can you give us exactly what you want to accomplish? There may be a better way to do the job.
How's my programming? Call 1-800-DEV-NULL
Offline
zhurai wrote:...ok, maybe my subject wasn't too good
Yeah, not so good. Please use descriptive thread titles so that others may be able to benefit from this thread.
not sure exactly what to call it `-`
Maybe you mean something like this?
main.sh
blah.sh Hello World
blah.sh
echo $*
tested it, but...not really =_=
Instead of using examples like blah.sh and main.sh can you give us exactly what you want to accomplish? There may be a better way to do the job.
well...really I was thinking of if it was possible... but it's like:
main.sh:
#! /bin/bash
./two.sh
#???
#???
#???
and
two.sh:
#!/bin/bash
read $1
print $1
how exactly would I get main.sh to input something like "Hello World" or whatever message into the read (as in, putting in *that* information w/o user input)
or however you say it ~_~
Offline
Maybe like this then?
main.sh
blah.sh Hello World
blah.sh
USERINPUT="$*"
print $USERINPUT
Or MUST it be using "read"?
Offline
Maybe like this then?
main.sh
blah.sh Hello World
blah.sh
USERINPUT="$*" print $USERINPUT
Or MUST it be using "read"?
well, read/Scanner (for java)/<STDIN> (for perl)/cin (for C++)/etc
~_~
Last edited by zhurai (2009-09-06 21:19:16)
Offline
oh, right.. one of the reasons I wanted to do this is because ssh requires a password, but isn't in the command line arguments from what I can see, thus I have to type it in every time/etc....
Offline
I'd recommend using ssh keys if you want passwordless login, but for what you describe Trent's solution seems right: you can feed stdinput to a script with
echo '123456' | blah.sh
Also - have a read about 'expect'.
Offline
Pages: 1