ksh script find command not printing any results


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh script find command not printing any results
# 1  
Old 02-07-2015
Wrench ksh script find command not printing any results

Hello,
Hitting a wall on this one. When at the command prompt it works fine:
Code:
# find /home/testuser -name 'PAINT*canvasON.txt'
/home/testuser/PAINT_canvasON.txt

# pwd
/home/testuser

# ls -l PAINT*canvasON.txt
-rw-r--r--    1 root     user              23 Feb 07 02:58 PAINT_canvasON.txt

But when I try to put it in a script I get no output. Here's the test script I've been using.
Code:
#!/bin/ksh

printf "Enter type: "
read A

find /home/testuser  -name '$A*canvasON.txt'

Also, my main goal is to create a script that will ask the user to input a type then search the /home/testuser directory for a file that has that type in the file name. If it does then it will cat the output of that file. If it doesnt then warn the user it doesnt exist.

Here's an example of what I would like to accomplish but it doesnt work:

Code:
#!/bin/ksh

printf "Enter type: "
read A

if [[ -n "$(find /home/testuser -name '$A*canvasON.txt')" ]]; then
  cat /home/testuser/"$A"_canvasON.txt
else
  echo "file does not exist"
fi

Ideal output if file exists:
Code:
Enter type: PAINT
This is the contents of PAINT_canvasON.txt

Ideal output if file does NOT exist:
Code:
Enter type: DUST
file does not exist

Please help, thanks
# 2  
Old 02-07-2015
Hi, try double quotes instead of single quotes, otherwise $A does not get resolved:
Code:
find /home/testuser  -name "$A*canvasON.txt"

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 02-07-2015
Ah yes that did the trick, thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find with rm command gives strange results

I want to remove any files that are older than 2 days from a directory. It deletes those files. Then it comes back with a message it is a directory. What am I doing wrong here? + find /mydir -mtime +2 -exec rm -f '{}' ';' rm: /mydir is a directory (2 Replies)
Discussion started by: jtamminen
2 Replies

2. Shell Programming and Scripting

Printing more info than find command gives out

Hi, I am trying to find files that are more than a gig with this command find . -size +1073741823c and it just gives me the names of the files. How do i get it to give me the actual size of the files too? ---------- Post updated at 09:41 AM ---------- Previous update was at 09:37 AM... (2 Replies)
Discussion started by: LilyClaro
2 Replies

3. Shell Programming and Scripting

Script to Execute command and mail results

HI everyone, I would like to have a script to run a certain linux command and mail the results or output of this command. This shell is to be later on set as cronjob. thanks in advance. (9 Replies)
Discussion started by: patrickminas
9 Replies

4. Shell Programming and Scripting

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... (10 Replies)
Discussion started by: sukhdip
10 Replies

5. Shell Programming and Scripting

problems with ksh array and find command

set -A allfiles `find $usrhtml -type f` i am trying to populate this array with the find command. It works fine when find is looking through a single directory but when i add a new subdirectory the files in the subdirectory get duplicated. Can anyone help me and fix this so each files in... (1 Reply)
Discussion started by: bjhum33
1 Replies

6. UNIX for Dummies Questions & Answers

Find command gave unexpected results

Hi, I recently executed a find command that caused unexpected permission changes and we had to do a full system restore. Can someone please explain what this command would do? find /staging/admin/scr * -exec chmod 755 '{}' + It caused file permissions inside / to be modified strangely. ... (1 Reply)
Discussion started by: poornima
1 Replies

7. Shell Programming and Scripting

Place 'find' results within TeX command

Hi, In an effort to collect all my .java-files and place them in a LaTeXfile (using the listings environment of latex), i tried to use ex. So what i have now is: find . -name "*\.java" > latex ex latex <<HERE %s/\(.*\)/\\lstinputlisting{\1} wq HERE So i try to escape the '\' with... (1 Reply)
Discussion started by: HannesBBR
1 Replies

8. Shell Programming and Scripting

FIND returns different results in script

When I execute this line at the command prompt I get a different answer than when I run it in a script? Any ideas on how to resolve? I'm trying to find all files/dir in a directory except files that start with the word file. Once I get this command to work, I will add the "delete" part to the... (6 Replies)
Discussion started by: blt123
6 Replies

9. Shell Programming and Scripting

edit results of a find command

Hi Purpose is to have a utility command to find and edit files . I tried a function like the following in my .profile file function vifind(){ find . -name $1 -print -exec vi {} \; } Is this correct? is there a better way to do it? I see this behaving a bit strange in case of AIX, and... (6 Replies)
Discussion started by: grep_whoami
6 Replies

10. Shell Programming and Scripting

Sending find command results to email

This is probably simple so forgive me... I just want to find all files in a folder created within the last 10 minutes... This is easy: # find /home/folder -cmin -10 If the find command locates any files created in the last ten minutes I want it to send an email alert. I just want to... (3 Replies)
Discussion started by: gardellap
3 Replies
Login or Register to Ask a Question