questions to a special ls


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers questions to a special ls
# 1  
Old 08-23-2009
questions to a special ls

Hi

Can anyone explain me in detail the following instructions (1st and 2nd line only)?

ls | \
while IFS= read filename
do
(some other instructions)
done

Thanks in advance.
Lazy
# 2  
Old 08-23-2009
The code:
Code:
ls |

is sending the output of the ls command onto the next command's input (stdin) rather than to the display.
The:
Code:
\

causes the shell to treat the following line as it it was on the same line, e.g.:
Code:
ls | \
more

is the same as:
Code:
ls | more

The line:
Code:
while IFS= read filename

causes each filename from the ls command to be used to set the variable ${filename} which can then be used in the code between the "do" and "done". The "IFS=" sets the separator character that is used to differentiate between one filename and the next.
If the separator is taken to be a space then the following would do the same but by replacing spaces with commas and then using a comma as the separator:
Code:
$ ls | sed -e 's/ /,/g' | while IFS="," read filename; do echo FILENAME = $filename; done

# 3  
Old 08-23-2009
Thanks Tony - you gave me a very understandable reply. Regards - Lazy
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Special character $$

Hi, on ksh What does the following do? grep -v "toolbox" $home_oracle/.profile >$home_oracle/.profile.$$ Thanks. Please use CODE tags as required by forum rules! (3 Replies)
Discussion started by: big123456
3 Replies

2. Shell Programming and Scripting

A special compare

Hi I use the following compare if }" == *"$vl"* ]]; then ... Can anyone tell me, how to code the compare for unequal? I got no results from google searches. Any hint or tip is welcome. Regards Lazy (5 Replies)
Discussion started by: lazybaer
5 Replies

3. Shell Programming and Scripting

Vi special character

When editing a file, vi displays a special character as ^L. Can you tell me the escaped character to be used in awk? And can that escaped character be used in a regexp in both sed and awk? (7 Replies)
Discussion started by: dmesserly
7 Replies

4. Shell Programming and Scripting

special characters

Hey guys, I'm trying to replace "]Facebook" from the text but sed 's/]Facebook/Johan/g' is not working could you please help me with that? (6 Replies)
Discussion started by: Johanni
6 Replies

5. Homework & Coursework Questions

Print questions from a questions folder in a sequential order

1.) I am to write scripts that will be phasetest folder in the home directory. 2.) The folder should have a set-up,phase and display files I have written a small script which i used to check for the existing users and their password. What I need help with: I have a set of questions in a... (19 Replies)
Discussion started by: moraks007
19 Replies

6. UNIX for Dummies Questions & Answers

I need a special print

I have this: \2009_may\05-04-2009\05-04-2009(74) \2009_may\05-04-2009\05-04-2009(74)\05-04-2009(74)_0-999 \2009_may\05-04-2009\05-04-2009(74)_left \2009_may\05-04-2009\05-04-2009(74)_left\05-04-2009(74) \2009_may\05-04-2009\05-04-2009(74)_right... (3 Replies)
Discussion started by: kenneth.mcbride
3 Replies

7. Shell Programming and Scripting

Special character \

Hi, In the shell script, i need to remove the special charater "\" with "\\". For example, i need to replace "D:\FXT\ABC.TXT" with "D:\\FXT\\ABC.TXT". However, when trying to do something like , i get the below error :- -->echo "D:\FXT\ABC.TXT" | sed -e 's#\#\\#g' sed: 0602-404 Function... (7 Replies)
Discussion started by: amit_arora
7 Replies

8. UNIX for Dummies Questions & Answers

special characters

I have one file which is named ^? ( the DEL character ) I'd like to know how to rename or copy the file by using its i-node number TYIA (2 Replies)
Discussion started by: nawnaw
2 Replies
Login or Register to Ask a Question