It all looks pretty good to me, although I don't know anything about
isql.
The pattern you're using is called a
here document. In
bash, you can replace it with a
herestring, and shorten things up. At least if it's just a single command.
Code:
isql -v test <<<"$CMD"
The big question though is whether the external file redirect is necessary. It appears that
isql has a
batch mode, for example. Can you use that to print out some kind of status string to
stdout instead, perhaps?
Or does it issue a different exit code based on success or failure to connect? If so, you can skip the text capture and just test the command result directly. (Insert an "
echo $?" after a command to see what its exit code is.)
If you do need to capture the
stderr output like this, then we could still replace the file with a variable. Just redirect the command's
stderr to
stdout (rather than the whole script's) and capture that directly.
Code:
exit_txt=$( isql -v test <<<"$CMD" 2>&1 )
if [[ -n $exit_txt ]]; then
....
It's recommended, BTW, to use
[[..]] for string/file tests, and
((..)) for numerical tests. Avoid using the old
[..] test unless you specifically need POSIX-style portability.
http://wiki.bash-hackers.org/commands/classictest
http://wiki.bash-hackers.org/syntax/...nal_expression
http://mywiki.wooledge.org/ArithmeticExpression