for f do exec <"$f"
: handle stdin
done
A non-interactive shell will treat any redirection from a file that cannot be read or that does not exist when associated w/ a special builtin as a fatal error and exit immediately with a meaningful diagnostic message written to stderr. So either your parameters are valid, readable files and the above statement will do nothing useful until you replace the : ...
part w/ something useful, or the user has provided an invalid parameter and the script exits meaningfully.
When you do...
for var in ...; do : compound command list on "$var"; done
The in ...;
bit is an optional statement in the syntax which enables you to substitute a parameter set for the default set - which is your argument list.
So...
for var do : compound command list on "$var"; done
...is probably what you're looking for, here.
for f do exec <"$f"
: now do some stuff w/ stdin
done
...where the shell will iteratively assign to stdin and validate as readable files any arguments provided your script for all commands that follow the exec
statement until all parameters are exhausted and the for
loop is done
. If it cannot do this then it will format and print your error message for you in a standard form to which the user is already accustomed.
bash
script why do you call it assh ...
and not asbash ...
?bash
is called assh
. As long as you don't use the bash-specific features (which is typical for beginners) both ways work.