Dear all, I found I cannot use a variable name as the input of the command "cat" followed by piping the result. Could any body tell me how to solve the problem? cat $filename |\ while read line do echo "$line read from $filename" done
Dear all, I found I cannot use a variable name as the input of the command "cat" followed by piping the result. Could any body tell me how to solve the problem? cat $filename |\ while read line do echo "$line read from $filename" done
Try: while read line do echo "$line read from $filename" done < $filename Cheers, Gary B-)
And what's the problem? Your code works just fine (with bash). What does not work for you? --($:~)-- cat $filename | while read line ; do echo "$line read from $filename" ; done :set hlsearch read from .vimrc --($:~)-- echo $filename .vimrc BTW: That was UUOC. Better to do: while read line; do echo "$line read from $filename"; done < $filename Michael
Gary's solution is good for this specific problem. In the more general case, where there's no alternative to piping stdout into a loop, you'll avoid this problem by using ksh and not bash. -- Christopher Mattern NOTICE Thank you for noticing this new notice Your noticing it has been noted And will be reported to the authorities
Chris Mattern < XXXX@XXXXX.COM >: What problem? The code that's been posted by the OP works But you're right though, Garys solution is better than the one posted by the OP, as it avoids a UUOC. Anyway - I'd *really* be interested in knowing the problem you talk about. Michael Schmarck -- "You're just the sort of person I imagined marrying, when I was little... except, y'know, not green... and without all the patches of fungus." -- Swamp Thing
Hi, I am told not to use pipes (|) in my shell scripts because using pipe is an expensive operation. Is this true? Would I get better performance if I execute one instruction and assign its output to a variable and then use that variable in the second instruction? instead of doing both insturuction on one line and piping the output of the first instruction to the second one? Thanks Al
2.Checking Pipe Status Using Script At Comp.Unix.Shell FAQ
Hello, I want to write a shell script in bash, where I can pipe other commands and files through. Something like cat textfile.txt | myscript.sh myscript.sh should take the input and write it to a file. I tried it with read and a while loop, but if there are special characters in textfile.txt like backslashes, the output was allways not the same like the input. How can I do that? Best regards Marc
4.Copy files using filenames from text files with shell script or bash script
How can I do this???? I have the file "lista.txt", and this file have the next information: one.txt two.txt five.txt six.txt ------------------- This files exist in the same directory that "list.txt", I would like to copy this files to other directory Using Windows the batch file would be like this: for /f "tokens=*" %i in (list.txt) do copy "%i" destdir\ How can I do something like that in UNIX?? Best Regards
Users browsing this forum: No registered users and 48 guest