Reputation: 2869
I always run my shell with a command:
./shellName file1 file2
So, in the shell, I can refer file1 as $1 and file2 as $2. However, if I want to run the shell with this command
./shellName < file1 > file2
I tried to read the file1 as standard input and file 2 as standard output. How can I refer file1 and file2 in the shell script? Can I still use $1 and $2? Thanks in advance.
Upvotes: 1
Views: 1682
Reputation: 1
If you directing files in, I don't think that the script has the variables available to them, rather the text is read from file1 and used as input for the script and anything outputted will end up in file2
Upvotes: 0
Reputation: 33217
# read from file1
read LINE
# write to file2 line we just readed
echo $LINE
Upvotes: 3
Reputation: 16974
Any read
statement in your script will read from file1 and any echo/print
statement will write the output to file2. $1
and $2
will be empty
Upvotes: 1