So I am trying to automate the set up of an arch linux instance via a python fabric script like this:
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 occurs on the second run() call because of the $ sign in the $arch. This fabric function fails in line 2 because $ followed by a string is recognized by fabric as a config variable. But I actually want $arch to be understood as a literal in the
echo 'echo "Server = http://repo.archlinux.fr/$arch" >> /etc/pacman.conf' call in bash shell.
How do I “escape” from this fabric quirk and designate the $arch as a literal to be written into my pacman.conf file?
use echo with single quotes. That will prevent the shell from expanding
$arch.this should be equivalent to
quick testing: