Register
It is currently Thu Apr 24, 2014 8:00 am

Redefining IFS to something weird


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Tue Dec 07, 2010 11:41 am   

Joined: Mon Dec 06, 2010 5:27 pm
Posts: 9
I'm writing a bash script to copy a list of files and do some stuff to them. Basically, I have the code written that does what it needs to do, but I can't quite understand why it works. I was hoping someone could clear up my understanding a bit.

Code:
filelist=`ls ~/gpodder-downloads/*/* | grep -v .jpg$ | awk '{print "\""$0"\""}'`

IFS=`echo -en "\n\b"`


The first line generates a list of files. I wrap each line in quotes because they usually have spaces in the directory names.

The second line changes IFS, and I understand what IFS itself does. What I don't quite get is what the separator becomes with that echo statement. If I'm reading that correctly, the backspace will remove the newline and essentially the result is nothing? I found this solution on a web page somewhere, but it was years old and there was no real explanation.


Top
 Profile  
 PostPosted: Tue Dec 07, 2010 6:12 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
No idea why IFS is being set like this. The backspace does not delete anything, though, you can test it:
Code:
echo -ne 'X\n\bY' | cat -v

There is a shorter way how to set IFS in bash:
Code:
IFS=$'\n\b'


Top
 Profile  
 PostPosted: Tue Dec 07, 2010 9:07 pm   

Joined: Mon Dec 06, 2010 5:27 pm
Posts: 9
No it doesn't delete anything, how interesting.

Thanks for the shorthand, much cleaner way to do that. The \b did absolutely nothing useful.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP