shell script clarification


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script clarification
# 1  
Old 01-15-2011
shell script clarification

HI,
I wrote the below script to find the files by geeting the input from the user like below
Code:
echo 'FINDING THE FILES IN THE CURRENT PATH'
read a
c=$a
echo 'THE FILE NAME IS' $c 'PLEASE COMFIRM with Y OR N'
read b
d=$b
echo $d
if [ $d =  'Y' ]
then
  echo `find . -name` $c
elif [ $d =  'N' ]
then
  echo 'TRY WITH NEW SEARCH'
else
  echo 'NO'
fi

I compiled the same but it it's not executing properly while am giving y also its quits and came out of the loop.

the output looks like this
Code:
FINDING THE FILES IN THE CURRENT PATH
thelak
THE FILE NAME IS thelak PLEASE COMFIRM with Y OR N
y
y
NO

Please help!

Thanks
Thelak Kumar

Last edited by Scott; 01-15-2011 at 09:48 AM.. Reason: Code tags
# 2  
Old 01-15-2011
Code:
#!/bin/bash
read -p "FINDING THE FILES IN THE CURRENT PATH : " a
read -p "THE FILE NAME IS' $a 'PLEASE COMFIRM with Y OR N : " b
if [ "$b" = "Y" ]
then
	find . -name "$a"
elif [ "$b" = "N" ]
then
	echo 'TRY WITH NEW SEARCH'
else
	echo 'NO'
fi


Last edited by Leo Gutierrez; 01-15-2011 at 01:12 PM..
# 3  
Old 01-15-2011
if i tried to execute the above query it displays below error,kindly clarify
Code:
forum.sh: read: 0403-039 No query process for pipe.
forum.sh[2]: read: 0403-039 No query process for pipe.
NO


Last edited by Scott; 01-15-2011 at 09:48 AM.. Reason: Code tags
# 4  
Old 01-15-2011
I'm using bash, which shell are you using?

Code:
leo@leo-desktop:~/Escritorio$ bash shell.sh 
FINDING THE FILES IN THE CURRENT PATH : camel.ico
THE FILE NAME IS' camel.ico 'PLEASE COMFIRM with Y OR N : Y
./raes/camel.ico
leo@leo-desktop:~/Escritorio$

# 5  
Old 01-15-2011
(In "ksh" "read -p" tries to read from a pipe. The error message looks like ksh on AIX).

Here is your script modified to introduce the loop you require while retaining all your original logic. I have also corrected the syntax of the "find" command and both "if" statements.
The loop is a do-done loop using the "break" command to exit.

Code:
while true
do   echo 'FINDING THE FILES IN THE CURRENT PATH'
   read a
   c=$a
   echo 'THE FILE NAME IS' $c 'PLEASE COMFIRM with Y OR N'
   read b
   d=$b
   echo $d
   if [ "$d" =  'Y' ]
   then
     find . -name $c -print
   elif [ "$d" =  'N' ]
   then
     echo 'TRY WITH NEW SEARCH'
   else
     echo 'NO'
     break
   fi
done

# 6  
Old 01-16-2011
Quote:
Originally Posted by thelakbe
HI,
I wrote the below script to find the files by geeting the input from the user like below
Code:
echo 'FINDING THE FILES IN THE CURRENT PATH'
read a
c=$a
echo 'THE FILE NAME IS' $c 'PLEASE COMFIRM with Y OR N'
read b
d=$b
echo $d
if [ $d =  'Y' ]
then
  echo `find . -name` $c
elif [ $d =  'N' ]
then
  echo 'TRY WITH NEW SEARCH'
else
  echo 'NO'
fi

I compiled the same but it it's not executing properly while am giving y also its quits and came out of the loop.

the output looks like this
Code:
FINDING THE FILES IN THE CURRENT PATH
thelak
THE FILE NAME IS thelak PLEASE COMFIRM with Y OR N
y
y
NO

Please help!

Thanks
Thelak Kumar
Consider that `Y' is not the same as `y'
# 7  
Old 01-16-2011
If you want to allow both "Y" and "y", try a case statement:

Code:
while true
do
   echo 'FINDING THE FILES IN THE CURRENT PATH'
   echo 'ENTER FILENAME'
   read a
   c="$a"
   echo "THE FILE NAME IS $c PLEASE CONFIRM with Y OR N"
   read b
   d="$b"
   #echo $d
   case "$d" in
         y|Y)
            find . -type f -name "$c" -print
            ;;
         n|N)
            echo 'TRY WITH NEW SEARCH'
            ;;
         *)
            # Answer was not Y/y/N/n
            echo 'EXITING'
            break
            ;;
   esac
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable clarification

what is the significance of %%.ksh in processname and %.ksh in processname_1 variable? Why is it returning same value?How is it working? processname=Testabc export processname=${processname%%.ksh} echo $processname #It is returning Testabc export processname_1=${processname%.ksh} echo... (2 Replies)
Discussion started by: vamsi.valiveti
2 Replies

2. UNIX for Advanced & Expert Users

Clarification about redirecting

Hi AM Using Unix Aix Used ${CMD} 2> ${ERR} Dont get what above statement works . SCRIPT=`basename $0` ERR=$PWD/$SCRIPT.err DATE=`date +"%d/%m/%Y"` CMD=2 ${CMD} 2> ${ERR} if then echo "SUCCESS" else echo "FAILURE" fi (1 Reply)
Discussion started by: Venkatesh1
1 Replies

3. HP-UX

su command clarification

Hi, I want to use the "SU" command in script it is asking me to enter the password manually. pleas the say the syntax of su command in single line that includes username/password. :) (3 Replies)
Discussion started by: vigneshwaran007
3 Replies

4. UNIX for Advanced & Expert Users

Need Clarification

Hi All, I have a file cleanlogs_imgp01_files which has the contents as follows, cold_log|/opt/elf/cold_spool get_orion_log|/opt/elf/logs get_coldFiles_log|/opt/elf/logs get_coldFiles_TuesToSat_log|/opt/elf/logs get_coldFiles_MonToSat_log|/opt/elf/logs And when i execute this, I get the... (1 Reply)
Discussion started by: DevM
1 Replies

5. Shell Programming and Scripting

Clarification on if loop in Shell scripting

Hi, I'm using Ksh and I'm seeing some of code in my programme as given below. Could you please let me know whats is this meeaing ? (I'm new to this unix) grep "1034" /u/kkk/bin/temp5.lst|cut -c1-2 >/u/kkk/bin/temp6.lst if then echo "" ... (2 Replies)
Discussion started by: shyamu544
2 Replies

6. UNIX for Advanced & Expert Users

Need clarification

We are facing problem while executin below script, cat $PIPE_FILE | imscp - "${LRX_FILE_LOC}" 2>&1 | tee "${LIST_DIR}/${IMSCP_OUT_FILE}" & sqlplus -s ${REPORTING_CONNECT} <<EOF whenever sqlerror exit 1 rollback spool ${PIPE_FILE} start ${LRX_EXEC_SQL} ${LRX_MDL_RUN_DATE} spool off exit... (4 Replies)
Discussion started by: samiks14
4 Replies

7. Shell Programming and Scripting

need some clarification on for loop in shel script

for ( ( $i=0 ; $i<=6 ; $i++ ) ) do p=/RSA-Data/PE-data00"${i}" echo "$p" done --- i need output as below /RSA-Data/PE-data000 . . . /RSA-Data/PE-Data006 (1 Reply)
Discussion started by: mail2sant
1 Replies

8. Web Development

Clarification

:confused: Hi All, i am new to unix....so i am not sure whether i am asking the related question with our forum.. My question .....Can anyone explain me about the CGI script is it something related to Unix or Linux or some other language. Thanks in advance Sha (1 Reply)
Discussion started by: Shahul
1 Replies

9. Shell Programming and Scripting

need clarification about tr -d command ?

Hi , I need your help to know the exact operation of this following code .. cat file1 | ux2dos | tr -d ''>>file2 file1 contains only one line : "DTS-PO\SPECTRUM WO 56" the data contains a META CHAR "\" .. look at the above line. But , The file2 output contains :... (7 Replies)
Discussion started by: vparunkumar
7 Replies

10. Shell Programming and Scripting

Need clarification

Hi All, I am using Korn Shell HP UNIX and i am writing my scripts with filename extension as ksh or sh .. I want to know what is the difference if i am giving ksh and sh Other thing when we execute the shell script either we make it as executable and run directly else we give '.' or 'sh'... (2 Replies)
Discussion started by: ravi.sadani19
2 Replies
Login or Register to Ask a Question