Python improper string quote -
Python improper string quote -
hi embedding shell script in python wanna execute echo args where
args = """-ne '#!/bin/sh\n\ update_bridge_config () {\n\ if [ $data_bridge_if ]; then\n\ echo "data_bridge_if $data_bridge_if"\n\ sudo /usr/bin/ovs-vsctl --may-exist add-br "br-$data_bridge_if"\n\ fi\n\ }\n\ eth0_mac_addr=`ip link show eth0 | awk '/ether/ {print $2}'`\n\ eth1_mac_addr=`ip link show eth1 | awk '/ether/ {print $2}'`\n\ eth2_mac_addr=`ip link show eth2 | awk '/ether/ {print $2}'`\n\ ' >> myscript.sh""" when open file found particular line getting changed
eth0_mac_addr= 'ip link show eth0 | awk /ether/ {print }'
any thought missing ?
edit:: ` getting replaced ‘ . , ‘ missing $2
it's single quote issue because starting single quote right after ne """-ne '#!/bin/sh ... . because of not getting $2 , facing other single quote abnormalities.
use '"'"' escape '
eth0_mac_addr=ip link show eth0 | awk '"'"'/ether/ {print $2}'"'"'
this should work. mind ! issue not pythonic shell
python string shell quotes
Comments
Post a Comment