我發現這個腳本:可變重定向在bash與ksh的
#!/bin/bash
readvar() {
while read -r line
do
declare "$line"
done < "$1"
echo ${!2}
}
在這裏: Bash Read Array from External File
我有一個名爲test.txt文件:
_127_0_0_1=kees
如果我這樣做in bash:
readvar ./test.txt _127_0_0_1
我得到的輸出:(聲明在ksh中不工作,所以我用排版取代它)
kees
但是如果我做同樣的事情在ksh中, :
#!/bin/ksh
readvar() {
while read -r line
do
typeset "$line"
done < "$1"
echo ${!2}
}
readvar ./test.txt _127_0_0_1
我得到輸出:
$ ./test.sh
./test.sh: syntax error at line 8: `2' unexpected Segmentation fault: 11
這是爲什麼?我怎樣才能使它在ksh中工作? (ksh93的爲此事)
'$ KSH --version 版本SH(AT&T研究所)93u 2011-02-08' – azbc