echo 不显示正确的输出
echo does not display proper output
以下代码读取 test.txt 内容并根据第一个字段将第三个字段重定向到 result.txt
src_fld=s1
type=11
Logic_File=`cat /home/script/test.txt`
printf '%s\n' "$Logic_File" |
{
while IFS=',' read -r line
do
fld1=`echo $line | cut -d ',' -f 1`
if [[ $type -eq $fld1 ]];then
query=`echo $line | cut -d ',' -f 3-`
echo $query >> /home/stg/result.txt
fi
done
}
以下是test.txt的内容:
6,STRING TO DECIMAL WITHOUT DEFAULT,cast($src_fld as DECIMAL(15,2) $tgt_fld
7,STRING TO INTERGER WITHOUT DEFAULT,cast($src_fld as integer) $tgt_fld
11,DEFAULT NO RULE,$src_fld
一切正常,除了 result.txt 中的输出是 $src_fld 而不是 s1。谁能告诉我代码中有什么问题吗?
尝试替换下面的行
echo $query >> /home/stg/result.txt
用这个
eval "echo $query" >> /home/stg/result.txt
以下代码读取 test.txt 内容并根据第一个字段将第三个字段重定向到 result.txt
src_fld=s1
type=11
Logic_File=`cat /home/script/test.txt`
printf '%s\n' "$Logic_File" |
{
while IFS=',' read -r line
do
fld1=`echo $line | cut -d ',' -f 1`
if [[ $type -eq $fld1 ]];then
query=`echo $line | cut -d ',' -f 3-`
echo $query >> /home/stg/result.txt
fi
done
}
以下是test.txt的内容:
6,STRING TO DECIMAL WITHOUT DEFAULT,cast($src_fld as DECIMAL(15,2) $tgt_fld
7,STRING TO INTERGER WITHOUT DEFAULT,cast($src_fld as integer) $tgt_fld
11,DEFAULT NO RULE,$src_fld
一切正常,除了 result.txt 中的输出是 $src_fld 而不是 s1。谁能告诉我代码中有什么问题吗?
尝试替换下面的行
echo $query >> /home/stg/result.txt
用这个
eval "echo $query" >> /home/stg/result.txt