I am attempting to write a korn shell script that does the following, but I am getting errors. I'm new to korn shell scripting and am not sure what I am doing wrong. Please help with example scripts. Thanks.
1) check for day of the week
2) if day of the week is Monday then check for the existence of three files
3) if all three files are not found then loop infinitely until all three are found
4) when found then execute a .sas program
5) else if the day if the week is not Monday then check for the existence of two files
6) if the two files are not found then loop infinitely until both files are found
7) when both files are found execute a .sas program
Here's what I have thus far:
#!/usr/bin/ksh
. ~/.profile
DAYOFWEEK=$(date +"%u")
echo DAYOFWEEK: $DAYOFWEEK
if ["$DAYOFWEEK" == 1];
then do
if [-f /files/are/here/FILE1.txt
-f /files/are/here/FILE2.txt
-f /files/are/here/FILE3.txt]; then
sas /files/are/here/process.sas
sleep 10
else if ["$DAYOFWEEK" !==1];
then do
if [-f /files/are/here/FILE2.txt
-f /files/are/here/FILE3.txt]; then
sas /files/are/here/process.sas
sleep 10
done
You can find some of your errors by using shellcheck :
In <yourfile> line 7:
if ["$DAYOFWEEK" == 1];
^-- SC1009: The mentioned parser error was in this if expression.
^-- SC1073: Couldn't parse this test expression.
^-- SC1035: You need spaces after the opening [ and before the closing ].
^-- SC1020: You need a space before the ].
^-- SC1072: Unexpected ";". Fix any mentioned problems and try again.
It will be an iterative process to avoid cascades of error messages.
Some details for shellcheck :
shellcheck analyse shell scripts (man)
Path : /usr/bin/shellcheck
Version : 0.3.4
Type : ELF 64-bit LSB executable, x86-64, version 1 (SYS ...)
Help : probably available with -h
Repo : Debian 8.11 (jessie)
Home : http://hackage.haskell.org/package/ShellCheck (pm)