简体   繁体   中英

ksh: evaluate a line read from file

I have got a properties file - prop that has the below line:

table1_prop=$USER.table1;dir1;dir2

In my script I read the file but I am unable to evaluate $USER.

while read record_line; do
   if [ ! -z "$record_line" -a "$record_line" != " " ]; then
          record_array=(`echo eval "$record_line" | cut -d '=' -f 2| sed 's/;/\n/g'`)  
   fi
done

Evaluate doesn't work. I tried backquote `. Any help.

I know it's been a while...but if you still have the problem...that code works with the property file you've provided.

    #!/bin/ksh

    while read record_line
    do
       if [[ ! -z $record_line && $record_line != " " ]]; then
            set -A record_array $(sed 's|;| |g' <<<"${record_line#*=*}")
       fi
    done < ./prop.txt

    for ((i=0;i<${#record_array[*]};i++)); do
            print $i" "${record_array[$i]}
    done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM