1

How to use filename arguments or default to stdin, stdout (brief)

view story
linux-howto

http://unix.stackexchange.com – I want to handle filenames as arguments in a bash script in a cleaner, more flexible way, taking 0, 1, or 2 arguments for input and output filenames. when args = 0, read from stdin, write to stdout when args = 1, read from $1, write to stdout when args = 2, read from $1, write to $2 How can I make the bash script version cleaner, shorter? Here is what I have now, which works, but is not clean, #!/bin/bash if [ $# -eq 0 ] ; then #echo "args 0" fgrep -v "stuff" elif [ $# -eq 1 ] ; then #echo "args 1" f1=${1:-"null"} if [ ! -f $f1 ]; then echo "file $f1 dne"; exit 1; fi fgre (HowTos)