0

I am trying to execute a script and its throwing "File Not Found" error. Below is my script

#!/usr/bin/ksh
export ROOT_ENV=dev
export ROOT_DIR=/files/$ROOT_ENV/windows/mp
export SRC_DIR=$ROOT_DIR/mp1
mail_id='abc@xyz.com'

if [[ -e "$SRC_DIR"/*_PO ]]
then
        echo "File exist"
        exit 0
else
       echo "File not found"
       exit 1

echo "Hello User,

File does not exist in the "$SRC_DIR".
Please place the file in the path : "$SRC_DIR"

Thanks,
Team

" | mail -s "Warning:  <"$ROOT_ENV="> <INFA> <PACK> FILE DOES NOT EXIST in path '$SRC_DIR'" $mail_id

echo "File does not exist"
fi 
done

Appreciate if some one can help here. Thanks,

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Arun.K
  • 103
  • 2
  • 4
  • 21
  • ksh scripts are not bash scripts. Tag ksh, use ksh in the title. – Charles Duffy Dec 03 '20 at 23:31
  • Beyond that -- make sure your code is a [mre], the _shortest possible thing_ that exits with the same error. If it has the same error when you take out the "mail_id" assignment, for example, then you should take out that assignment. – Charles Duffy Dec 03 '20 at 23:33
  • And beyond that, `[[ -e "$SRC_DIR"/*_PO ]]` isn't going to work as you expect. A glob expression can't be used in a context that expects only exactly one file. – Charles Duffy Dec 03 '20 at 23:33
  • ...to the extent that that's your problem, it's a duplicate of [check if a file exists with wildcard in shell script](https://stackoverflow.com/questions/6363441/check-if-a-file-exists-with-wildcard-in-shell-script), as discussed in [BashFAQ #4](http://mywiki.wooledge.org/BashFAQ/004). – Charles Duffy Dec 03 '20 at 23:34

0 Answers0