A few suggestions.
In the beginning you have a filename passed to the script. You test it with -z, which instead you should use -r (see `man test`). That'll show if the file exists and is readable.
In your functions you have arguments that aren't tested. Were the correct arguments and correct amount of arguments passed?
Do the values of those arguments have valid contents?
And there are further tests that can be done, based on the script specs. RegEx can be used too.
And you assume that the directory in which you are writing files does in fact exist and is writable.
Perhaps a check before writing?
I learned a long time ago: Assume Nothing.
You could also use touch to initialize a file. Or /dev/null.
In the beginning you have a filename passed to the script. You test it with -z, which instead you should use -r (see `man test`). That'll show if the file exists and is readable.
In your functions you have arguments that aren't tested. Were the correct arguments and correct amount of arguments passed?
Code:
myfunc(){if [ $# -ne 3 ]; thenecho "not enough arguments"fi}Code:
myfunc(){for x in "$@"; doif [ -z "$x" ];thenecho "No contents"fidone}And you assume that the directory in which you are writing files does in fact exist and is writable.
Perhaps a check before writing?
Code:
if ! [ -d "$dir" ]; thenecho "Not a directory"fiif ! [ -w "$dir" ]; thenecho "Directory not writable.fiYou could also use touch to initialize a file. Or /dev/null.
Statistics: Posted by valkyrie44 — Tue Feb 03, 2026 1:08 am