The issue is in your echo $NSTR
command: IFS
is still set to /
, so when $NSTR
undergoes word-splitting and file-name expansion, the stuff on either side of a /
becomes separate arguments to echo
.
To fix this, I recommend finding a better way to set ARY
to begin with, rather than starting with $FULLSTR
. Parameter-expansions such as $FULLSTR
should essentially always be quoted, because you essentially never want word-splitting and filename-expansion. (In your case you do want the word-splitting . . . but not the filename-expansion.)
If that's not an option — if your only way to set ARY
is by splitting $FULLSTR
— then you can write something like this:
OLDIFS="$IFS"
IFS=/
ARY=($FULLSTR)
IFS="$OLDIFS"
NSTR="/${ARY[2]}/${ARY[3]}"
echo "$NSTR"
Or, better yet, you can set NSTR
directly based on $FULLSTR
, and avoid ARY
except when you have no choice:
NSTR="/${FULLSTR#/*/}"
echo "$NSTR"