Sponsored Content
Full Discussion: Read statement not working
Top Forums Shell Programming and Scripting Read statement not working Post 302825009 by mohanalakshmi on Sunday 23rd of June 2013 02:00:53 AM
Old 06-23-2013
Code:
#!/bin/sh
current=/home_dir/a541101
#POfile=PO_NO.txt
error(){
echo "Do you want to enter PO again(Y/N):"
read answer
echo $?
case $answer in
Y) main;;
y) main;;
N) exit;;
n) exit;;
*) exit ;;
esac
}
main()
{
DATE=`date +"%m-%d-%y"`
if [ -f $current/temp.txt ]
then
rm $current/temp.txt
fi
if [ -f $current/PO_NO.txt ]
then
#cp $current/PO_NO.txt $current/PO_bk/PO_NO_$DATE.txt
rm $current/PO_NO.txt
fi
echo "Enter PO Numbers to create text file with entetred PO. Please type 'exit' when you finished entering"
while read line
do
if [ "$line" != "exit" ]
then
echo "$line" >> $current/temp.txt
else
break
fi
done
echo "Checking PO's wait for a while!!!!!!"
IFS=$'\n'
set -f
var=0
#for i in `cat temp.txt`
while read i
do
echo "$i"
var=`expr $var + 1`
len=`echo $i | wc -m`
#len=`expr $i : ".*"`
echo $var;
echo $len;
case ${i} in
*\ * ) echo "PO has at least one space in line number $var" ; error;
esac
if [ "$len" -gt 7 ]
then
echo "Error in PO,contains more than 7 char in line number $var with $len characters"
error
elif [ "$len" -lt 7 ]
then
echo "Error in PO hasless than 7 char in line number $var with $len characters "
 error
elif [ "$len" -eq 7 ]
then
echo $i >> $current/PO_NO.txt
fi
m=$var
done < temp.txt
echo "for loop over"
if [ -f $current/PO_NO.txt ]
then
echo "Output text file has been created check $current/PO_NO.txt for output file"
echo "PO_NO.txt contains $m lines";
fi
echo "Triggering the PO Publish script "
echo " "
}
main

Hi the above is my entire code, whenever i run this code by callig error read answer is not allowing me to enter user input.
when i execute the prog as sh name.sh its not working
but with bash name.sh
its working fine
thank u
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If statement not working

I understand this question probably poses some child like stupidity, but I can't get this if statement to work for love or money. #!/bin/ksh echo "Input either 1 or 2" read Num if ; then echo "Message 1" if ; then echo "Message 2" else echo "false" fi $ ksh decisions Input either 1... (6 Replies)
Discussion started by: Hazmeister
6 Replies

2. UNIX for Dummies Questions & Answers

until statement not working

im trying to write an until statement which dont go onto the next stage until the user inputs a certain phrase. It is then stored in an array. Ive come up with this code so far but its not working and i dont know why. read in1 until do echo "Incorrect, try again" ... (2 Replies)
Discussion started by: strasner
2 Replies

3. Shell Programming and Scripting

read statement not working in a function

Pls this is emergency.I have written a script which is taking input from another script. and the contents of my second script are acting as functions to my main script.Now the problem is that in one of the functions i want the script ececution to stop and start when user enters any character r... (2 Replies)
Discussion started by: sumitdua
2 Replies

4. Shell Programming and Scripting

Read statement not working in a script

I have a script consisting of certain functions whose input is a file at same location. In that file i have written the name of anothe file at same location. The third file contains a word which act as a function in the first script.Let me give an example i have a scrip file say 1.sh in which i am... (7 Replies)
Discussion started by: sumitdua
7 Replies

5. Shell Programming and Scripting

If statement is not working.

Hi. With the help of this group I have created a shell script to find the factorial of a number. OK. Then I got wild.;) I tried to put in a check to make sure the entry is a number. read num If )) then echo "This is not a valid number. Try again." fi while (( $var <= $num)) more... (5 Replies)
Discussion started by: Ccccc
5 Replies

6. Shell Programming and Scripting

Cshell if statement not working

Hi .I am trying to check the first arguments =-s and the third =-d,but it doesnt work ,any idea why It gives me if: Missing file name Thanks #case -s and files if( $1 == "-s" && $3 != "-d" ) then echo "case s" endif (1 Reply)
Discussion started by: lio123
1 Replies

7. Shell Programming and Scripting

If statement is not working in KSH

#! /bin/ksh rm -f ./xyz file --- this line is working // Below any if stmt is not working. if then echo " blah blah " fi or I replaced above if with if then echo "dir exists" fi This is also not working. I am new to KSH. So can someone help why if stmt is not... (31 Replies)
Discussion started by: saggy9583
31 Replies

8. UNIX for Dummies Questions & Answers

Read statement within while read loop

hi, this is my script #!/bin/ksh cat temp_file.dat | while read line do read test if ]; then break else echo "ERROR" fi done when i execute this code , the script does wait for the user input . it directly prints "ERROR" and terminates after the no. of times as there... (3 Replies)
Discussion started by: siva1612
3 Replies

9. Shell Programming and Scripting

[Solved] While read line and if statement not working

I'm looking for some help in figuring why my little bit of code will not process any entries other then the first one in my list. while read line ;do hostname=${line//\"} a=`ssh user@$hostname uptime;echo $?` if ];then dt=`date` touch... (6 Replies)
Discussion started by: whegra
6 Replies

10. Shell Programming and Scripting

Bash read input in case statement not working as expected

I'm having an issue with bash read input when using a case statement. The script halts and doesn't read the input on the first loop. if I hit enter then the scripts starts to respond as expected. Need some help here. defaultans=8hrs read -e -i $defaultans -p "${bldwht}How long would you like... (5 Replies)
Discussion started by: woodson2
5 Replies
All times are GMT -4. The time now is 05:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy