Monday, March 30, 2009

BASH Scripting - Take input from file as STDIN

# Save the STDIN file descriptor
0>&3

# Redirect file as STDIN
0< filename

# Do stuff
...

# Close the file descriptor
exec 0>&-

# Assign STDIN back to 0
3>&0

No comments: