Using "sh" means you're executing the script in posix-compatibility mode. It may still be ksh
, but restricted in features, or it may be a different shell entirely. You'll almost always want to use the full #!/bin/ksh
shebang unless you really need portability.
, and the command substitution that goes with it, is unnecessary, since every major shell has at least basic parameter substitutions
$(..) is highly recommended over `..`
QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS
. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.
And learn how to format effectively too. At the very least indent your subsections.
Scripting With Style
if [[ $1 = "start" ]] ; then
echo "Writing $ADG_svrname" >> tlog.txt
#Final note, my links are all to bash
sources, but almost all of it applies equally to ksh
within ADG_svrname.var, I am more interest of getting the value within this file and set it as a variable.
Show us the contents of the file then. Is it a single line, or multiple, or what?
is usually the command to use. Assuming there's only a single line:
read -r variable <filename
For multiple lines you'll probably have to use a while loop.
How can I read a file (data stream, variable) line-by-line (and/or field-by-field)?