bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

IFS is ignored for nested functions with stdin redirection


From: Andrey Borzenkov
Subject: IFS is ignored for nested functions with stdin redirection
Date: Sun, 2 Dec 2012 20:52:00 +0400

I hit this problem in DKMS code and could reduce it to the following
example:

======
#!/bin/bash

oifs=$IFS

inner () {
        echo a/b/c/d
        exit 0
}

outer() {
for i in 1; do
        IFS=/ read m v k a < <(IFS=$oifs inner)

echo $m:$v:$k:$a
done
}

outer

for j in 1; do
        IFS=: read a b c d
done < <(outer)

echo $a-$b-$c-$d
=========
bor@opensuse:/tmp> ./t
a:b:c:d
a/b/c/d---
bor@opensuse:/tmp> 
=========


Now insert *any* redirection before call to inner in outer function.
It magically starts to work again:

=========
#!/bin/bash

oifs=$IFS

inner () {
        echo a/b/c/d
        exit 0
}

outer() {
for i in 1; do
        : > /dev/null
        IFS=/ read m v k a < <(inner)

echo $m:$v:$k:$a
done
}

outer

for j in 1; do
        IFS=: read a b c d
done < <(outer)

echo $a-$b-$c-$d
========
bor@opensuse:/tmp> ./t
a:b:c:d
a-b-c-d
bor@opensuse:/tmp> 
========

This is bash on openSUSE 12.2, bash-4.2-51.6.1.x86_64. Anyone can
reproduce it as well?

-andrey



reply via email to

[Prev in Thread] Current Thread [Next in Thread]