"Escaping" $ when executing a remote bash command from python fabric

So, I am trying to automate the creation of the linux arch instance through the python script fabric as follows:

from fabric.api import run, sudo

def server_setup_communityrepo():
    run('echo \'echo "[archlinuxfr]" >> /etc/pacman.conf\' | sudo -s')
    run('echo \'echo "Server = http://repo.archlinux.fr/$arch" >> /etc/pacman.conf\' | sudo -s')
    run('echo \'echo " " >> /etc/pacman.conf\' | sudo -s')
    sudo('pacman -Syy yaourt --noconfirm')

The problem arises in the second call run()due to the $ in sign $arch. This fabric function does not work on line 2 because $, followed by a line, is recognized as a configuration variable. But I really want $ arch to be understood as a literal in

echo 'echo "Server = http://repo.archlinux.fr/$arch" >> /etc/pacman.conf' a call in the bash shell.

How can I "escape" from this trick quirk and designate $ arch as the literal that will be written to my pacman.conf file?

+5
source share
1 answer

. $arch.

run('echo \'Server = http://repo.archlinux.fr/$arch\' | sudo -s tee -a /etc/pacman.conf')

echo 'Server = http://repo.archlinux.fr/$arch' | sudo -s tee -a /etc/pacman.conf

:

>>> import os
>>> os.system('echo \'Server = /foo/$arch\' ')
Server = /foo/$arch
0
+4

All Articles