2012-04-08 84 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