You are not logged in.

#1 2012-10-11 11:26:56

Crispinmg
Member
Registered: 2012-10-11
Posts: 2

Error with a variable variable

Hi people!

First of all, sorry for my bad english ;-)

I have a vert rare problem. I'm implementing a shellscript to sync svn dirs that are out of actual revision. This script checks automatically which dirs are candidates and into a for iteration he's going building the final svnsync command. This part works ok, but when the recently created command becomes executed he doesn't do any thing. Here is the part of the code that do this task:

                command=""
                c=1
                for i in $optionP;do
                        SVN_SYNC_CMD="svnsync sync http://server/$i $CREDS --no-auth-cache --non-interactive >> $ERROR_SYNC 2>&1"
                        SVN_SYNC_FORMAT="echo \"###### i$ ########\" >> $ERROR_SYNC"
                        command="${command} $SVN_SYNC_FORMAT && $SVN_SYNC_CMD"
                        if [ "$c" != "$CONT" ]; then
                                command="${command} &&"
                                c=$(expr $c + 1)
                        else
                                command="${command} &"
                        fi
                done
                $command
                echo "Final Command ========== >>>$command"
                $DIALOG --title 'Sincro...' --tailbox $ERROR_SYNC 50 95

The last echo "Final Command ======>>> $command" shows me the correct command, like this: echo "#################################TestDir#################################" >> /var/tmp/errorSync && svnsync sync http://server/TestDir  --username=user --password=anything --no-auth-cache --non-interactive >> /var/tmp/errorSync 2>&1 && echo "#################################TestDir1#################################" >> /var/tmp/errorSync && svnsync sync http://server/TestDir1 --username=user --password=anything --no-auth-cache --non-interactive >> /var/tmp/errorSync 2>&1 &

If I execute this command directly from the shell works ok, but when this command is executed from the script it crashes and the script seems to do the first echo, with a output like this "#################################TestDir#################################" >> /var/tmp/errorSync && svnsync sync http://server/TestDir  --username=user --password=anything --no-auth-cache --non-interactive >> /var/tmp/errorSync 2>&1 && echo "#################################TestDir1#################################" >> /var/tmp/errorSync && svnsync sync http://server/TestDir1 --username=user --password=anything --no-auth-cache --non-interactive >> /var/tmp/errorSync 2>&1 &      instead to continue with the next command...

Anybody knows what can I do?


Thanks in advance!

Offline

#2 2012-10-11 11:38:50

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Error with a variable variable

Use eval $command

Example:

--> command='echo test > test.txt'
--> $command
test > test.txt
--> eval $command
--> cat test.txt
test

Offline

#3 2012-10-11 11:50:24

Crispinmg
Member
Registered: 2012-10-11
Posts: 2

Re: Error with a variable variable

I'm a big fool!

I've tried to do with eval many times before writing this post, but I tried with other combinations of eval and obviously did not work ... I was so dazed with this stupid problem that it occurred to me that ...

Thank you very much Procyon

PD: I Love google translator jajajaja

Offline

#4 2012-10-11 15:00:54

karol
Archivist
Registered: 2009-05-06
Posts: 25,425

Re: Error with a variable variable

Please remember to mark the thread as solved https://bbs.archlinux.org/viewtopic.php?id=130309

Offline

#5 2012-10-17 00:41:10

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 5,661

Re: Error with a variable variable

Please use code tags - it makes stuff much easier to read.


How To Ask Questions The Smart Way | Help Vampires

Arch Linux | x86_64 | GPT | EFI boot | grub2 | systemd | LVM2 on LUKS
Lenovo x121e | Intel(R) Core(TM) i3-2367M CPU @ 1.40GHz GenuineIntel | Intel Centrino Wireless-N 1000 | US keyboard with Euro | 320G 7200 RPM Seagate HDD

Offline

Board footer

Powered by FluxBB