Can't use 'read' in 'if-condition'


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can't use 'read' in 'if-condition'
# 1  
Old 09-19-2006
Can't use 'read' in 'if-condition'

Hi,

I'm having this problem, it seems that I can't read a value in an if-condition.
First line of my script
"#!/bin/ksh"

Now if I do the following, for some kind of reason he does skip the 'read go_on', I'm not able to give input when he executes this, he just goes on executing the script. I've seen some examples where they use the 'read' in an 'if-condition' so I suppose that I must do something wrong

if [ -d $version ]; then
echo ""
echo "Directory voor deze versie bestaat reeds"
echo "Bent u zeker dat u verder wilt gaan? (y/n)"
echo "------------------------------------------"
echo ""
echo "Uw keuze: \c"
read go_on

if [[ $go_on != 'Y' && $go_on != 'y' ]]; then
QUIT_EXEC
PRINT_END
exit
fi
else
echo ""
echo "Directory wordt aangemaakt"
mkdir /interfaces/LD1/DOC1_42/RESOURCE/$app_input/VersieManagement/$version
mkdir /interfaces/LT1/DOC1_42/RESOURCE/$app_input/VersieManagement/$version
mkdir /interfaces/LP1/DOC1_42/RESOURCE/$app_input/VersieManagement/$version
fi
# 2  
Old 09-19-2006
The read command reads from standard-in, not /dev/tty. So if you do:
./your_script < input.file
the read will just read from input.file. You probably need to do:
read go_on < /dev/tty
to force it to read from the terminal.
# 3  
Old 09-20-2006
Thx a lot Perderabo,
it's working fine now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read Two Columns - Apply Condition on Six other columns

Hello All, Here is my input univ1 chr1 100 200 - GeneA 500 1 0 0.1 0.2 0.3 0.4 0.5 univ1 chr1 100 200 - GeneA 600 1 0 0.0 0.0 0.0 0.0 0.1 univ1 chr1 100 200 - GeneA 700 1 0 0.4 0.4 ... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

2. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

3. Shell Programming and Scripting

Read a file and write to new file with some condition

Hi.... I have a data file, which I want to split and write to new file...it looks like this... Column1 column2 Column 3 1 28.25 36.42 -----Read 5 28.26 36.42 10 28.23 36.43 15 28.22 36.43... (1 Reply)
Discussion started by: nex_asp
1 Replies

4. Shell Programming and Scripting

Read column from file and delete rows with some condition..

Hi.... I have a need of script to do delete row whenever condition is true.... 2.16 (3) 1 3 9999 0 (1) (0) 34.42 (4) 1 3 9999 37 (2) (3) 34.38 (4) 1 3 9999 64 (2) (3) 34.4 (4) 1 3 1 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

5. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

6. Shell Programming and Scripting

Read 2 files alternatively based on condition.

Experts, What would be the code in ksh/perl to read 2 files alternatively, based on the following condition. while reading file 1 we check if a blank line is encountered, if yes, then we read file 2 unless a blank line is encountered in file 2 if we have a blank line in file 2 we come back... (3 Replies)
Discussion started by: suraj.sheikh
3 Replies

7. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

8. Shell Programming and Scripting

To read the values and to use in the where condition

Hi, I have the below values in a text file. 'xx.16397950', 'xx.16397957', 'xx.16397976', 'xx.16473259', I need to use in the where clause of the sql query in my unix shell script. How to read one by one value. It should be like this: select * from <<table name>> where xx in (... (10 Replies)
Discussion started by: venkatesht
10 Replies

9. Shell Programming and Scripting

Read file based on condition

Hi Friends, Can any one help with this: I have a huge file with the format as A SAM 4637 B DEPT1 4758 MILAN A SMITH 46585 B DEPT2 5385 HARRYIS B SAMUL 63547 GEORGE B DANIEL 899 BOISE A FRES 736 74638 I have to read this file and write only the records that starts with "B" only ... (5 Replies)
Discussion started by: sbasetty
5 Replies

10. Shell Programming and Scripting

need to read a file and keep waiting till it satisfies some condition

In my script i am writing to a counter file the no of processes i had started, that is each time i start a process, i will increment the content of counter file and also when the process ends i will decrement the content of the file. after this i do some other activities, by now i want to... (1 Reply)
Discussion started by: senthilk615
1 Replies
Login or Register to Ask a Question