File watcher script

if test -n "$(find/data/path/ 'filename.txst' -print-quit)
then 
  echo "file found"
  exit 0
else
  echo "file not found"
  exit 46
fi

So I basically looking to understand the

if test -n "$(find/data/path/ 'filename.txst' -print-quit)

line.
Pls help to elaborate what this command is doing.

I think it must be find /data/path , not find/data/path . Also, -print -quit not -print-quit

What it does is it looks inside /data/path for all files named 'filename.txst' (did you mean txt?) and prints their names. The -quit makes it exit after it prints the first name.

So it's looking for the first file it can find named filename.txst.

1 Like

Thanks alot

---------- Post updated at 02:47 PM ---------- Previous update was at 02:41 PM ----------

what does this code mean
Any help appreciate...

base_file=$(basename $latest_file)

Returns the base file name of a string parameter.

Basically it strips out the extra stuff and just gives you the file name:

 basename /u/dee/desktop/cns.boo 

returns cns.boo

You can do a

man basename

to get more info on your system. The man pages are your friend.

1 Like

It removes /path/to/ from /path/to/file and just gives you 'file'.

1 Like

Along with above this is another code line, which I am unabel to understood, because there is no rc_1 is define in the script above..

rc_1=$?
echo 'Return Code Basename :' $rc_1
echo '+-------------------------------+'

Please use code tgs as required by forum rules!

The rc_1 is defined in that snippet you post, by assigning the last command's (or pipe's) exit code to it. Read the man page of your shell.

1 Like