Friday, 13 November 2009

bash IFS

I don't want internal field seperator to be default as my echo redirection to a file is tab seperated output of ls cmd list of files.So,this is what i did using IFS to set to the new line delimiter at the end of every ls line output.



IFS=$'\r' ;echo $(find . -type f -size 0 -exec ls -l {} \;) > /tmp/zerosize-files


some tips i got from ubuntu forums :


$ IFS=$' \t\n' FOO=$'a b\tc\nd-e'; echo $FOO
a b c d-e
$ IFS=' ' FOO=$'a b\tc\nd-e'; echo $FOO
a b c
d-e
$ IFS=$'\t' FOO=$'a b\tc\nd-e'; echo $FOO
a b c
d-e
$ IFS=b FOO=$'a b\tc\nd-e'; echo $FOO
a c
d-e

No comments:

Post a Comment

Tweets by @sriramperumalla