Unable to set/reset IFS

I have Ubuntu 16.04.6 (Edit: Now updated to 16.04.7), with bash 4.3.48(1)-release (x86_64-pc-linux-gnu). I am not able to set/reset my IFS variable. I have tried to set is using the literal CTRL+V and as well. Even tried unset.

Interestingly, the behaviour the same for any other variable ($Other_IFS below).

Any pointers?

Below is the output of my attempts:

mike@laptop:~ $ cat -vte <<< $IFS
$
mike@laptop:~ $ IFS=$' \t\n'
mike@laptop:~ $ cat -vte <<< $IFS
$
mike@laptop:~ $ IFS=" ^M"
mike@laptop:~ $ cat -vte <<< $IFS
$
mike@laptop:~ $ unset IFS
mike@laptop:~ $ cat -vte <<< $IFS
$
mike@laptop:~ $ IFS=" ^M"
mike@laptop:~ $ cat -vte <<< $IFS
$
mike@laptop:~ $ Other_IFS=" ^M"
mike@laptop:~ $ IFS="$Other_IFS"
mike@laptop:~ $ cat -vte <<< $IFS
$
mike@laptop:~ $ cat -vte <<< $Other_IFS
$

Edit: (based on some of the comments, I am adding an example):

The data file: (TAB separated)

Col1 Col2 Col3
312 19 [1,1,3,2]
763 1 [2,3,0,8] 12 104 [3,0,0,3]
150 208 [3,0,2,3]

I am sorting the file on Col1 and getting the values of Col2 and Col3 of the last entry (after sorting), in an array. Then I am printing the array values separately. Here is the command used to achieve this:

max=($(sort -t $'\t' -n -k1,1 my_file | cut -d $'\t' -f2,3 | tail -1))
echo ${max[1]}

In the above example, the output is

[2,

instead of [2,3,0,8].

At the beginning of the script, I have already added

OFS="$IFS"
IFS=$'\t'

and at the end,

IFS="$OFS"

NoteOn a different system (Ubuntu 20.04.1, bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)), the script is producing an expected output.

6 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like