What is wrong with this script? I'm not a strong UNIX scripter, but this is for my job. I get the error: 'else' unexpected.
#!/bin/ksh
INIT=/h
DEST=/h/data
if [-n $1]
echo "usage: $0 %26lt;filename%26gt; : no filename given"
exit 1
else
if [-f $1]
echo "performing operation"
#SKIPPING ALL THE USELESS INFO
exit 0
else
echo "$1 has errors or does not exist"
exit 2
fi
fi
My problem is with the error handling...the if-thens. I don't understand them.
Solaris 8 UNIX script help!?
Few things are wrong:
1) "if" should be followed by 'then' : if [...] ; then
2) Put a space between "[" and "-n" - it matters, because "[" is implemented as command and -n is its argument
3) First condition is better written as -z "$1" - otherwise it won't work if first parameter is not specified. Use "man test" to learn more about those conditions.
#!/bin/ksh
INIT=/h
DEST=/h/data
if [ -z "$1" ]; then
echo "usage: $0 %26lt;filename%26gt; : no filename given"
exit 1
else
if [ -f "$1" ]; then
echo "performing operation"
#SKIPPING ALL THE USELESS INFO
exit 0
else
echo "$1 has errors or does not exist"
exit 2
fi
fi
Reply:doesn't Korn require a 'then' clause?
if [ condition ] then
...
else
...
fi
I also think your else-if command should be 'elif [ condition ] then'
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment