Problem with find command at ksh

Hi!

I made a shell script which is offering menu choice. I made it on RHEL & then with little bit changes I was able to run successfully on AIX/ksh.
Script is working fine with no issues other than a little one i.e., There is one choice in which I can list out and delete some files from a directory as per userinput. If there are files it listing and deleting without any problem but if there ain't any files then its displaying one error.
i.e.,
find: 0652-019 The status on 1_*.* is not valid.

Here is my script:

#!/usr/bin/ksh


script_menu() {
while :
       do
       clear
echo ----------------------------------------------
echo   ************Script Start Menu************
echo ----------------------------------------------
echo Run from the following Scripts
echo   
       echo [1] xyz.sh
       echo [2] abc.sh
       echo [3] Return to Main Menu
       echo [4] Exit
echo ----------------------------------------------
read choice
case $choice in
1)
       echo Run xyz script file; /backup/test1/xyz.sh;
       echo Press Enter; 
       read x;;
       
2) 
       echo Run abc script file; /backup/test1/abc.sh;
       echo Press Enter; 
       read x;;
3)     
       return;;
4)
       exit;;
    esac 
 done
}


#Main Menu
while :
       do
       clear
       echo ----------------------------------------------------
       echo    ******************Main Menu******************
       echo ----------------------------------------------------
       echo Select a Choice
       echo [1] Run the Scripts
       echo [2] View the Current Run Numbers
       echo [3] Amend the Run Numbers
       echo [4] Check Status of propagation 
       echo [5] Turn Propagation on or off
       echo [6] View Log Files
       echo [7] List files in import directory
       echo [8] Clear files from import directory
       echo [9] Exit
       echo ----------------------------------------------------
       echo Select choice {1-9}:
read choice

case $choice in
1)
       script_menu;;

2) 
       echo Current Run Number; cat /backup/test1/run_number.txt; 
       echo Press Enter; 
       read x;;

3)     echo Enter Run Number;
       read -r  userinput; echo $userinput > run_number.txt; 
       echo Press Enter;
       read x;;  
4)
       echo Propagation Status ; cat /backup/test1/auto_pro.txt; 
       echo Press Enter; 
       read x;;

5)
       echo Change Propagation ; echo Enter Value; read -r  userinput; echo $userinput > auto_pro.txt; 
       echo Press Enter; 
       read x;; 

6)     
       echo View Log files; 
       echo Enter Log file name;
       read -r filename ; echo $filename | ls -l | find "$filename"_*.* -type f ! -name ".*" | awk '{print}'; 
       echo Press Enter; 
       read x;;
7)
       echo List files in import directory;
       echo Enter file name;
       read -r filename ; echo $filename | ls -l | find "$filename"_*.* -type f ! -name ".*" | awk '{print}';
       echo Press Enter; 
       read x;;
8)
       echo Clear files from import directory;
       echo Enter File Name;
       read -r filename ; echo $filename | ls -l | find "$filename"_*.* -type f ! -name ".*" -exec rm -f {} \;
       echo Press Enter;
       read x;;
9)   
       exit;;
*) 
       echo Invalid Number
       

    esac
done


option number 6,7,8 are giving above error, If there is no files with the name as input by user.
How can I solve this? Plz help !!

Thanks,

why do you use find with "_*.*" ?

This is the file name pattern. file will be in this format e.g., 1_abc.txt, 2_xyz.txt and so. thats why I'm using "_*.*"

try change to this and re-try

# find -type f \( -name "$filename"_*.* -a ! -name ".*" \)

Its giving me this error:

Usage: find [-H | -L] Path-list [Expression-list]

Its not even able to find the present files.:frowning:

You probably don't have GNU find.
Try to give the path where you want to search for.

find /path/to/search -type f \( -name "$filename"_*.* -a ! -name ".*" \)

or

find . -type f \( -name "$filename"_*.* -a ! -name ".*" \)

for current directory.

can you add a path

# find $PATH -type f \( -name "$filename"_*.* -a ! -name ".*" \) ....

As per my understanding, command is working fine(which one I used). B'coz on RHEL machine its showing 5_*.: No such file or directory
but on AIX machine its showing find: 0652-019 The status on 1_*.
is not valid.
Context is the same of both saying.
So what I'm thinking to do(now) that How can I put a customized message like: "No file with this name", when there is no file.
Plz help me with that.

---------- Post updated at 05:09 AM ---------- Previous update was at 05:01 AM ----------

I tried:

if [$? -nq 0] | awk '{print}' | else echo " File not found"

I knew it would through an error. and So it did :slight_smile:
I need help with this :slight_smile:

3-4 days to a thread....no reply for the questions :(:(:frowning: what happened Unix Gurus...plz help

change like this

.................
.............
....|find "$filename"_*.* -type f ! -name ".*" 2>errorlog|....
if [ -s errorlog ] ; then echo "No file with this name";fi
.................
.............

thanks alot @ygemici it is working....