Mu code output will be
In the above one i need to check the input untill it match 7 char
but when its more than 7 i need give option y/Y pompt not waiting for user input
You have been told multiple times that error() is reading from temp.txt rather than from your keyboard. Having you repeat that error() is not reading from your terminal is not going to change the fact that you cannot have an interactive discussion with a user at a terminal while you are reading input from a file instead of from the terminal.
Last edited by Don Cragun; 06-23-2013 at 04:37 AM..
I repeat: You cannot have an interactive discussion with a user at a terminal while you are reading input from a file instead of from the terminal.
The logic of your script makes no sense.
Do you want to read a list of PO numbers from a file and save the subset of those PO numbers that meet your validation criteria in a file ($current/PO_NO.txt)? Or, do you want to have an interactive session with someone sitting at a terminal typing in PO numbers, saving PO numbers they type in that meet your validation criteria in the same file?
Choose one of the above! The mixed approach you are currently using cannot work.
Processing the list of validated PO numbers is a separate problem we can address after you come up with a way to get a list of validated PO numbers.
Here is an alternative to your script that I think does what you were trying to do. It will interactively read a list of PO numbers if standard input for the script is a TTY, and will read a list of PO numbers from a pipe or regular file without prompting if the input is not a TTY. Each line of input will be checked to see if it contains 7 non-space characters and if it does, it will be added to a file containing validated PO numbers; otherwise the reason why the line was not accepted will be written to standard output.
This script will not work with /bin/sh on a Solaris 5.10 system, but will work with any ksh, bash, or other POSIX-conforming shell (including /usr/xpg4/bin/sh and /usr/xpg6/bin/sh on Solaris systems). This script assumes that the directory you specified by the variable current contains a subdirectory named PO_bk (which was present in comments in your script) and saves the the previous run's results in a file in that directory with the backup file's name including the date AND TIME when the backup is created.
Hopefully this will give you some ideas that you can use to create a script that will work for you.
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)
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)
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)
#! /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)
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)
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)
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)
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)
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)
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)