redirect STDIN

can you redirect STDIN with command arguments?

I have tried this approach:

# ./script -option <argument1> <argument2> 0<$2 
# $2: ambiguous redirect

Is this possible?

myscript.sh arg1 < arg2

works from the command line that what you need?

nope.

in bash, it still tries to read arg2 as a text file:

# script -option arg1 < arg2
# arg2: No such file or directory

Hi

I am not clear with your exact requirement. If i am not mistaken, by default your input is going to be from STDIN.

One point to say here. Inside a shell script if there is any redirection of the standard input to a file, then subshells, functions and everything else also inherit the changed file descriptor. After that statement, your read will not get input from STDIN. In that case, you could use a read as mentioned below:

read newinput < /dev/tty

If think this is what you are asking for. If not, please provide the script you faced the problem, which would help to analyze and provide better solution saving time.

I am trying to automate the script without changing the script, or without waiting for the script to run, then inputing the STDIN from keyboard, tty, etc.