Shell scripts issue
Hi all,
My scripts looks like this .. when i execute this script its says file does not exist even though file is present physically and if the file does not present in the file system then the output is null. I am wrong somewhere .. ?? echo " enter file " read name for i in `find /apps12i -type f -name $name -printf %f ` do if [ -e $i ] then echo "file exists" else echo "not exists " fi done 2. I want to send multiple attachments using mutt is possible ? 3. I want to change from mail address when i am sending mails through mutt. Regards |
use a while read loop instead
Code:
find ... | while read file |
You will get a better response to questions 2 and 3 if you put them in separate threads with relevant titles.
Regards the existing file(s) that is/are reported as not existing you can see which files are being tested by changing the code to Code:
echo " enter file " Regards null output for non-existing files, that is expected. The find command will not produce any output so the loop code will not be executed. BTW:
|
Thanks for your reply .. but i am not able to understand proplery
I have rewritten like this .. but still the same problem exists . can you please correct me. I request you to please elaborate this while IFS= read -r -d '' this stmt. echo " enter file " read name i=`find /apps12i -type f -name $name -print0` | while IFS= read -r -d '' $i do echo $i done Quote:
|
Code:
echo " enter file " |
Thanks for your reply ..... what if file does not exist .. my requirement is , if the file does not exist it should give me files does not exist message.
Regards Quote:
|
You changed
Code:
find /apps12i -type f -print0 | while IFS= read -r -d '' i Code:
i=`find /apps12i -type f -name $name -print0` | while IFS= read -r -d '' $i while IFS= read -r -d '' means "set IFS to the empty string and with that setting in use for this command only, run the "read" shell built-in command not treating any \ characters specially and only accepting the newline character as end-of-line indicator. The shell uses the characters in IFS as word-separators when parsing input into "words". The net effect of all this gobbledygook is to transfer exactly the file names that "find" prints, regardless of any weird characters in file names. It is very defensive and robust. Most of the time ghostdog74's suggestion works perfectly well -- and is a lot simpler! :) |
Quote:
Code:
echo " enter file " |
i have executed this but .. the output is wrong ..
even though file exists .. its giving me file not found. i am really sorry please bare with me .. testinst1.koel.co.in/apps12i]./check.sh enter file bala.txt File 'bala.txt' not found testinst1.koel.co.in/apps12i]./check.sh enter file APXVDRAL.rdf /apps12i/oracle/KIRAN/apps/apps_st/appl/ap/12.0.0/reports/US/APXVDRAL.rdf File 'APXVDRAL.rdf' not found Regards Quote:
|
Quote:
Sorry my stupid mistake -- the "while" loop is run in a subshell so any variables set in it are lost when it exits. :redface: This one is tested Code:
echo " enter file " |
Thank you !! very much. Finally it worked.
But i didn't understand the logic behind this .. can you please explain this. echo " enter file " read name while read FILE do if [[ "$FILE" == '' ]]; then echo "$name not found" else echo "$FILE found" fi done <<< $( find . -type f -name "$name" ) Regards Quote:
|
Quote:
If the file does not exist, there is no output from the find command so the string is empty, hence the if [[ "$FILE" == '' ]]. It's easier to read your code if you put it in code tags (that's a link to instructions or you may prefer to use "Advanced Edit" mode which has a # button for code tags). |
Thanks .. nice explanation .
Regards Quote:
|
Hi Catkin,
My requirements seems to be changed again . I will explain you what i am trying to achieve. I want to find multiple files in different directories with one find command and send this files to developers. This is my requirement and changed the code accordingly but it seems to be not working . Code:
echo " enter how many files " testinst1.koel.co.in/apps12i]./check.sh enter how many files 1 enter file bala.txt ./check.sh: line 12: syntax error near unexpected token `done' ./check.sh: line 12: `done <<< $( find . -type f -name "$name" )' Regards Bala Quote:
|
|
All times are GMT -5. The time now is 04:22 PM. |