read command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read command
# 8  
Old 07-22-2005
Hi guys

blowtorch has perhaps right! or are my environment variables not right??
It's very strange because the only manner that the 'read command' run on my box is like so:
Code:
echo "enter a number"
read number
echo $number

Anyway.. thanks for your help
ny
# 9  
Old 07-22-2005
Quote:
Originally Posted by nymus7
Hi guys

blowtorch has perhaps right! or are my environment variables not right??
It's very strange because the only manner that the 'read command' run on my box is like so:
Code:
echo "enter a number"
read number
echo $number

Anyway.. thanks for your help
ny
Not strange at all. That is the expected result and it's explained by that FAQ article that r2007 quoted. A pipeline like:
somecommand | read variable
doesn't work because a subshell is spawned to execute that read command. That subshell sets "variable" and then it exits. The original shell now resumes and it doesn't have a copy of the value of "variable".

That syntax works in ksh because the Korn shell arranges that when the last command in a pipeline is a shell built-in command, that command is run in the context of the cuurent shell. This means that despite appearances ksh will not treat "somecommand | read variable" as true pipeline. This feature works in ksh alone. Not even pdksh supports this syntax and this is the most frequently reported pdksh "bug".
# 10  
Old 07-22-2005
Ok, great! That's means that many commands in my ksh script will don't run in bash!
How to know the difference between the ksh and the bash shell and wich commands will products a subshell??
What's the best way to learn the bash shell because I've seen on internet some bash tutorial but they don't speak about subshell and many commands are described like ksh?
What's means "pdksh"??
:-)thanks
# 11  
Old 07-22-2005
There's a lot of stuff that is different between bash and ksh. pdksh is a shell that was written to be as close as possible to ksh. Unlike ksh, pdksh is open source. Get a good ksh book and a good bash book and read them both. Then write a few hundred shell scripts in both languages. At that point the differences will seem clear.
# 12  
Old 07-22-2005
Well, I've understood... Smilie
Thanks Perderabo and have a nice weekend!
nymus
# 13  
Old 07-23-2005
Quote:
Originally Posted by nymus7
Thanks for your reply!
But my script doesn't run with new syntax : read var << echo $(vmstat 1 1 |...)
I've read on the bash manuel that the read command is a "Bash Builtin Commands" and should running like in other shell.
What's that means? Is bash a restrictive shell...?
I'll must to change all my AIX scripts for my linux box :-( really a bad things
Regards,ny
be careful, there should have a blank character between the two "<"s
read var < < echo $(vmstat 1 1 |...)
# 14  
Old 07-25-2005
Hi r2007

I'm receiving the following error with a blank character between the two "<"s
-bash: syntax error near unexpected token `<'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Read command

Trying to use the read command. How do you add a 2nd option? In this example I'd like to offer two options, pre and post. If you answer pre, you get one output but if you answer post, you get another output. echo Is this pre or post? read pre if then echo You have typed pre. fi (6 Replies)
Discussion started by: jimmyf
6 Replies

2. UNIX for Beginners Questions & Answers

Need help with read command

Is there a way to make the input of the read command (or some similar command that I'm unaware of) not visible, or with an astrix?? An example: #!/bin/bash # Example echo; echo "Who are you??"; read name if ; then echo "Welcome, the terminal is yours."; exit else "Stranger... (2 Replies)
Discussion started by: Huitzilopochtli
2 Replies

3. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

4. Shell Programming and Scripting

read command

Hello guys, I am trying to a script that reads from key board and use the entered value in the next step. Example: enter folder name read $folder (i will give work) cd /main/$folder/ pwd it should print /main/work ---------- Post updated at 03:31 PM ----------... (1 Reply)
Discussion started by: sharath24
1 Replies

5. UNIX for Dummies Questions & Answers

read command - using output from command substitution

Hey, guys! Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek: So, I wanted to use a command statement similar to the following. This is kinda taken... (2 Replies)
Discussion started by: ProGrammar
2 Replies

6. UNIX for Dummies Questions & Answers

Read command

Hi everyone, I have problem while writing a shell script for linux (Red Hat). First I need to create a read command. I tried to google this but so far I can't sort this out. I hope you will be able to help me. I have to read a file like this : GESTION_DATA_SET_variable1_variable2 ... (2 Replies)
Discussion started by: Aswex
2 Replies

7. Shell Programming and Scripting

read command

Is there a way to use the READ command and force the user to enter a non-zero length string? If the user enters a zero length string the user input is rejected. code: print "what is the answer: \n" read answer (2 Replies)
Discussion started by: djehresmann
2 Replies

8. Shell Programming and Scripting

read command in while

hi all iam not able use read command in the while loop in the following program while read line do echo $line echo "enter name" read name echo "your have entered $name" done < work.txt THE READ COMMAND INSIDE THE WHILE LOOP IS NOT WORKING, IS ANY OTHER WAY TO SOLVE THIS... (7 Replies)
Discussion started by: avi.skynet
7 Replies

9. Shell Programming and Scripting

Regarding read command

Hi all, What does -u option indicates in read command. while read -u var1 do . . done < file.txt (1 Reply)
Discussion started by: krishna_gnv
1 Replies

10. Shell Programming and Scripting

read command

I have file which is space filled likE below Note: here spaces are replaced by |. When I use read command to read this file all the spaces are truncated only the default space is not removed. The output is Note: here spaces are replaced by |. Can this default truncation be override? (4 Replies)
Discussion started by: COD
4 Replies
Login or Register to Ask a Question