How to set bash IFS to default?

  • Follow


If I do
OLDIFS=IFS
IFS=":"
.... do stuff
IFS=OLDIFS

it works as expected.

If at the end I set
IFS=" \t\n"
then IFS is not correctly reset and redirection fails:

LOGFILEPATH=/var/log
LOGFILE=${LOGFILEPATH}/logging
echo "status" >> ${LOGFILE}

gives ambiguous redirect.

If the logfile name doesn't have an n in it works OK.

However doing this interactively works OK.

What is the correct way of setting IFS to space tab newline?
0
Reply daniothefish 9/23/2003 11:10:52 AM

Dan Pidcock wrote:
[...]
> If at the end I set
> IFS=" \t\n"
> then IFS is not correctly reset and redirection fails:
> 
> LOGFILEPATH=/var/log
> LOGFILE=${LOGFILEPATH}/logging
> echo "status" >> ${LOGFILE}
> 
> gives ambiguous redirect.
> 
> If the logfile name doesn't have an n in it works OK.

Learn about the different kinds of quotes. The one you need here
is $'...'. Neither "..." nor '...' expand escape sequences.

IFS=$' \t\n'

And remember to always put double quotes around variable
references:

echo status >> "$LOGFILE" # however note that in this particular
                          # case, it's only necessary with the
			  # bash shell

To set the default behavior, you can also � unset IFS �.

-- 
St�phane
0
Reply Stephane 9/23/2003 11:30:18 AM


1 Replies
868 Views

(page loaded in 0.025 seconds)

Similiar Articles:













7/23/2012 4:46:33 PM


Reply: