ksh: file to string expansion fails if ksh called with stdin closed
Issue
- String expansion fails if ksh called with stdin closed.
- Refer scripts below to reproduce issue i.e. "demo" and "demo.sub"
"demo" script contents:
#!/bin/ksh
exec <&- 2>/dev/null
$0.sub
"demo.sub" contents:
#!/bin/ksh
tmpfile=/tmp/wrk-$$
echo "Hello World" > $tmpfile
wc -c $tmpfile
a=$(<$tmpfile)
echo ${#a}
a=$(<$tmpfile)
echo ${#a}
rm $tmpfile
- Script does not work
[root@vm201 mtest]#
[root@vm201 mtest]# ./demo
12 /tmp/wrk-1025
0
11
- Without closing stdin in main (demo) script all works as expected.
[root@vm201 mtest]# more demo
#!/bin/ksh
#exec <&- 2>/dev/null
exec 2>/dev/null
$0.sub
[root@vm201 mtest]# ./demo
12 /tmp/wrk-1020
11
11
Environment
- Red Hat Enterprise Linux 6
- ksh-20120801-10.el6.x86_64
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.