That I know. The point is, IFS should not kick in, inside of "" double quotes, as they protect each variable from IFS, as well as '' single quotes. (but inside them vars don't expand, as all is literal)gordon@ said:... Since 2 is in the IFS variable, it's expanded as a field separator. ...
Yes I want IFS to split string on each char 2 (two) and 0 (zero).wblock said:IFS is a list of characters. Do you really want "2" and "0" to be field separators?
...
Seeker said:That I know. The point is, IFS should not kick in, inside of "" double quotes, as they protect each variable from IFS, as well as '' single quotes. (but inside them vars don't expand, as all is literal)
To sum it:
echo "${#str}" -> Should echo '2'
echo ${#str} -> Should echo '' null/empty string
#! /bin/sh
set -x
IFS=2
str='st'
echo 'LEN:'
bar="${#str}"
echo "$bar"
bar=${#str}
echo "$bar"
# IFS [B]doesn't[/B] kicks in
echo [B]"[/B]${str%edit*}[B]"[/B]
# IFS [B]does[/B] kick in
echo ${str#*edit}
# IFS [B]doesn't[/B] kicks in
echo [B]"[/B]$num[B]"[/B]
# IFS [B]does[/B] kick in
echo $num
[color="Red"]# IFS goes right through [B]"[/B][/color]
echo [B]"[/B]${#str}[B]"[/B]