I found this script:
#!/bin/bash
readvar () {
while read -r line
do
declare "$line"
done < "$1"
echo ${!2}
}
Over here: Bash Read Array from External File
I have a file called test.txt:
_127_0_0_1=kees
If I do in bash:
readvar ./test.txt _127_0_0_1
I get the output:
kees
However if I do the same thing in ksh, (Declare doesn't work in ksh so I replaced it with typeset.) :
#!/bin/ksh
readvar () {
while read -r line
do
typeset "$line"
done < "$1"
echo ${!2}
}
readvar ./test.txt _127_0_0_1
I get the output:
$ ./test.sh
./test.sh: syntax error at line 8: `2' unexpected Segmentation fault: 11
Why is that ? And how can I make it work in ksh? (ksh93 for that matter)