|
From: | gmail |
Subject: | Re: GNU Parallel Bug Reports parallel can't ressigned variablen in the same context in same file |
Date: | Thu, 31 May 2012 18:02:21 +0800 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 |
On 05/30/2012 11:11 PM, Andreas Bernauer wrote:
thanks your reply ahead. AndreasOn 5/29/12 11:26, gmail wrote:hello is it a bug to parallel or parallel can't do like this ? today , i used parallel to my shell script ,but read all the document,no referent about variable ouside parallel. bash test code like that: ################### #!/bin/bash foo=33 parallel "foo=44;echo $foo;" above code response 44 ####################For me, your code works as I'd expect it: - $foo gets expanded to 33 before parallel is even run, because '$foo' is in double quotes ("), not single quotes (') - parallel does not run anything but awaits input from the terminal, printing a message about this circumstance. ############# $ cat /tmp/par #!/bin/bash foo=33 parallel "foo=44;echo $foo;" $ bash /tmp/par parallel: Input is read from the terminal. Only experts do this on purpose. Press CTRL-D to exit. ^D $ bash /tmp/par parallel: Input is read from the terminal. Only experts do this on purpose. Press CTRL-D to exit. 1 ^D bash: 1: command not found 33 ############# Note the output '33' after bash's complain. If you want to use foo in your parallel script, you must take care that '$foo' is not expanded in the parallel script, for example by escaping the '$' sign or putting the command in single quotes. Example for the former: ##################### $ cat /tmp/par2 #!/bin/bash foo=33 parallel "foo=44;echo \$foo;" $ bash /tmp/par2 parallel: Input is read from the terminal. Only experts do this on purpose. Press CTRL-D to exit. 1 ^D bash: 1: command not found 44 ################### Note that now the output is '44' after bash's complain. HTH, Andreas. My aim is that shell variable which in parallel can modify in the whole shell script context , the sample code below like that: enviroment : centos 5.5 x64 (bash 3.2.25) ############## #!/bin/bash domains=('www1' 'www2') counter=0 parallel -j 2 "if [ -z $counter ];then echo 'var no set ';fi;counter=$((counter + 1));echo $counter {1} " ::: address@hidden ############## the variable counter no to be increased when looping the array domains , counter should be 2,but in parallel it print zero( no changed) i hope i can describe my quesion for help above like that. |
[Prev in Thread] | Current Thread | [Next in Thread] |