4

I need to find out 3 files in my UBM unix directory,if any one(CMUSER) file is available means,then i need to exit from my unix script,

Below is my unix shell script logic. Why am I getting compilation error?

cd /$UBCS
if [ -f /$UBM/CSUSER.LOCKED -o -f /$UBM/CSUSER.START]
     -o f /$UBM/CSUSER.UPDATE ];
then
   exit;
fi

my compilation error below

Enter script to execute: atm-autopbf
/rd23/gilbat/R2016/ubcs/atm-autopbf[38]: test: 0403-021 **A ] character is missing**
.
/rd23/gilbat/R2016/ubcs/atm-autopbf**[39]: -o:  **not found.****

 Not running C/S (SHELMATE MAXSESSIONS=0). Aborting ...

Press <ENTER> to continue:
0

1 Answer 1

1

Your script,

cd /$UBCS
if [ -f /$UBM/CSUSER.LOCKED -o -f /$UBM/CSUSER.START]
     -o f /$UBM/CSUSER.UPDATE ];
then
   exit;
fi

has a syntax error. You have unbalanced [ ... ] in the if-statement. You also need a space between /$UBM/CSUSER.START and the following ].

#!/bin/sh

cd "/$UBCS" || exit 1

if [ -f "/$UBM/CSUSER.LOCKED" ] ||
   [ -f "/$UBM/CSUSER.START"  ] ||
   [ -f "/$UBM/CSUSER.UPDATE" ]
then
   exit
fi

Do try pasting your scripts into ShellCheck: https://www.shellcheck.net/

Also, you don't get compilation errors for shell scripts (as they are not compiled). They are parsing errors.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.