osx - When change $IFS in bash on Mac OS X -
i met problem when change value of $ifs in bash on mac os x. example, have main directory /xxx/xxx/xxx, , 2 sub-directories subdir1 , subdir2. if run shell script
maindir=/xxx/xxx/xxx; subdirs=$(find $maindir -type d -maxdepth 1); echo $subdirs normally results this
/xxx/xxx/xxx/subdir1 /xxx/xxx/xxx/subdir2 these 2 subdirectories separated blankspace. problem is, when change once $ifs value this:
oldifs=$ifs; ifs=$'\n'; ifs=oldifs; after that, if check again value of $subdirs
echo $subdirs the results become
/xxx/xxx/xxx/subdir1 /xxx/xxx/xxx/subdir2 it seems bash automatically changes blankspace \n. bothers me. there solution change \n blankspace? system mac os x version 10.7.5.
you didn't reset ifs (or set oldifs in first place):
oldifs="$ifs" ifs=$'\n' ... ifs="$oldifs" (this fails restore ifs unset state if unset prior saving "value", that's not worth going here.)
Comments
Post a Comment