0
我試圖在變量中存儲命令的結果,但無法弄清楚正確的語法。此命令的工作perferctly:將命令的結果存儲在變量中
echo "-868208.53 -1095793.57 512.30" | cs2cs +init=esri:102067 +towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56 +to +init=epsg:4326
這是怎麼了,我試圖用這個例子,它適用於我的數據,但outcord
分配是錯誤的:
#!/usr/bin/bash
filename="$1"
while read -r line
do
name=$line
a=($name)
coord= ${a[1]} ${a[2]}
outcoord= $("echo $coord | cs2cs +init=esri:102067 +towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56 +to +init=epsg:4326")
echo $outcoord
done < "$filename"
樣的錯誤,我得到:
remap.sh: line 7: -515561.05: command not found
remap.sh: line 8: echo | cs2cs +init=esri:102067 +towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56 +to +init=epsg:4326: command not found
remap.sh: line 7: -515542.01: command not found
remap.sh: line 8: echo | cs2cs +init=esri:102067 +towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56 +to +init=epsg:4326: command not found
樣本數據:
1 -515561.05 -1166540.03
2 -515542.01 -1166548.76
3 -515519.61 -1166552.19
4 -515505.29 -1166550.25
5 -515477.05 -1166546.82
6 -515431.12 -1166534.06
7 -515411.45 -1166517.39
如何將命令結果分配給變量outcoord
?
我試過了,但仍然收到錯誤:'remap.sh:line 7:-515561.05:command not found remap.sh:line 8:24d49'46.026「E:command not found' –
啊,我錯過了問題在線7.我認爲devnull的答案應該可以解決你的問題。 –