I want to make the file test condition a variable ($Prmshn in code below).
My goal is to use something like the first three unsuccessful if statetments since the 'if [[' is the newer style. Note: I copied the error message to the right of each of the three unsuccessful if statements.
My goal is to use something like the first three unsuccessful if statetments since the 'if [[' is the newer style. Note: I copied the error message to the right of each of the three unsuccessful if statements.
Code:
#!/bin/ksh
test_input()
{
Prmshn=${1}
InFLNm=${2}
ifReq="-$Prmshn $InFLNm"
#the following three if statments fail:
#if [[ -${Prmshn} ${InFLNm} ]] ; then #/testing/test.ksh: syntax error at line 8 : `${InFLNm}' unexpected
#if [[ $ifReq ]] ; then #/testing/test.ksh: syntax error at line 9 : `]]' unexpected
#if [[ "$ifReq" ]] ; then #/testing/test.ksh: syntax error at line 10 : `]]' unexpected
#the following six if statments are successful:
#if [ "$ifReq" ] ; then
#if [[ -r /input/test.txt ]] ; then
#if [[ -r $InFLNm ]] ; then
#if test -r $InFLNm ; then
#if test -$Prmshn $InFLNm ; then
if test $ifReq ; then
# each of the previous if statements were used in turn with the balance of the statement following:
echo "input file is now available."
else
echo "input file is not available."
fi
}
test_input r /input/test.txt