LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-06-2010, 10:28 PM   #16
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,122

Original Poster
Rep: Reputation: 46

It does surprise me. Seems a bit of an arcane to me.
If the # of filenames in LIST is N, I'd say, in post #14 the for is traversed N times, because I see the output includes N line terminators, output by the echo command. Hence control is transfered to first sentence in the loop just after echo printed |$i, this sentence being the echo sentence itself. It seems as if iteration had converted into recursion.
 
Old 12-06-2010, 11:20 PM   #17
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,478

Rep: Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888Reputation: 1888
No not nearly as exciting as you make it out to be
The inverted commas you have placed around "$LIST" has told the interpreter to preserve the whitespace.
So if you have the following scenario:
Code:
dir - u1.sh
    - u2.sh
    - u2 and 3.sh
    - u4.sh
Then by looking at the input in your script:
Code:
LIST="$(ls u*.sh)"
Here you expected the inverted commas to preserve the whitespace and hence each file above and its newline character have been concatenated together in the variable LIST.

Then when you use the following:
Code:
for i in "$LIST" ; do
Again you have used inverted commas so bash preserves all the whitespace and therefore places all the data into 'i'.
This of course then only has to run the for loop once and do a single echo.
 
Old 12-08-2010, 10:08 AM   #18
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,122

Original Poster
Rep: Reputation: 46
I see, I see. The fault in my reasoning was not seeing that newlines are whitespace too.

Reading bash's man page I discovered the trap DEBUG builtin command. In fact, there is a full set of debugging facilities. Thanks for your kind help.
 
  


Reply

Tags
copy, regular_files, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Files help script. da_bizkit Linux - Newbie 6 12-15-2009 08:10 PM
Creating a script to move or copy files into multiple directories below the files matthes138 Linux - Newbie 5 08-25-2009 04:57 PM
script to copy files scofiled83 Programming 9 07-06-2009 08:18 PM
Script to copy files defend Linux - Newbie 2 12-11-2008 10:56 AM
will this script copy only certain files? verbatim Programming 5 04-28-2005 09:28 AM


All times are GMT -5. The time now is 12:50 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration