shell - Reading full file from Standard Input and Supplying it to a command in ksh -


i trying read contents of file given standard input script. ideas how that? want is:

somescript.ksh < textfile.txt 

inside ksh, using binary read data "textfile.txt" if file given on standard input. ideas how "pass" contents of given input file, if any, binary inside script?

you haven't given enough information answer question, here few ideas.

if have script want accept data on stdin, , script calls else expects data passed in filename on command line, can take stdin , dump temporary file. like:

#!/bin/sh  tmpfile=$(mktemp tmpxxxxxx) cat > $tmpfile /some/other/command $tmpfile rm -f $tmpfile 

(in practice, use trap clean temporary file on exit).


if instead script calling command also expects input on stdin, don't have special. inside script, stdin of call connected stdin of calling script, , long haven't consumed input should set.

e.g., given script this:

#!/bin/sh  sed s/hello/goodbye/ 

i can run:

echo hello world | sh myscript.sh 

and get:

goodbye world 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -