I've got a script, ex myscript.sh, and it has to redirect to stdout what it gets from stdin (like a cat).
For example:
myscript.sh < myfile.txt > myfile2.txt
How to do this?
Also, how can i redirect the stdout in another file rather then myfile2.txt?
My tries:
I tried using:
echo $*
And it only works using:
myscript.sh | cat myfile.txt
If i use:
myscript.sh < myfile.txt
it prints out nothing
Best Answer
I cannot understand what you want: $* outputs the positional parameters and you did not supply any, so you got no output (apart from new-line).
cat
does not read standard input when it is given a file to list, somyscript.sh | cat myfile.txt
has the same effect asmyscript.sh ; cat myfile.txt
(not strictly true, but correct in terms of input/output).If you want your script to copy input to output, then it should contain simply
cat
.If you want output from $*, then you need to run
myscript.sh {parameters}
.And what do you mean by "redirect the stdout in another file rather then myfile2.txt"? You presumably don't mean
... > myfile3.txt
.