2012-04-08 83 views
2

我有以下bash腳本:Linux Bash。 2線有什麼區別?

1 #!/bin/bash 
2 query='query= SELECT * WHERE { ?s ?p ?o } LIMIT 5' 
3 cmd="curl $1 -s -d \"$query\"" 
4 echo "$cmd" 
5 # curl $1 -s -d "$query" 
6 # $cmd 

第5和第6行也必須這樣做。當我取消第五行的評論時,一切正常。但是,第六行沒有任何工作。

所以我想知道最新的區別?

謝謝。

+1

回顯「$ cmd」是什麼顯示? – 2012-04-08 19:02:18

+1

你試過'eval「$ cmd」'嗎? – 2012-04-08 19:04:27

+0

echo「$ cmd」顯示:curl http:// localhost:2001/sparql -s -d「query = SELECT * {}」 – 2012-04-08 21:04:04

回答

2

否;在第4行中,您只是通過「echo」它來顯示命令;第6行實際執行該命令。

E.g.

$eg="ls /var/www" 
echo $eg #This would literally return ls /var/www" 
$eg #This would return the directory listing of /var/www/ (actually run the command). 
+0

我確定OP已經明白這一點。請注意,該問題詢問第5行和第6行如何不同,而不是第4行和第6行如何不同。第4行似乎只是在調試。 – ruakh 2012-04-08 19:59:21