Hi everyone,
i have the following script.sh:
foo='lsusb | grep Webcam | cut -c16-18'
sudo /home/user/public/usbreset /dev/bus/usb/001/$foo
when i try to call this script from python using
subprocess.call("script.sh", shell=True)
it seems that only 'sudo /home/user/public/usbreset' is being executed. how can i fix this properly?
Thanks in advance!
RudiC
2
How do you tell that only the quoted line is executed?
uhm sorry, i meant to say that usbreset without the parameter
/dev/bus/usb/001/$foo
is being executed.
RudiC
4
Is the entire parameter missing or is just the $foo
empty?
well, your question has given me the answer as i used set -x to enable echo now, and the command is being executed as
sudo /home/user/public/usbreset /dev/bus/usb/001/lsusb | grep Webcam | cut -c16-18
So maybe i can use | to combine both commands into one line?
RudiC
6
You used apostrophes '
in lieu of backticks `
for the command substitution, so it failed and you had the literal string for the parameter.
---------- Post updated at 12:42 ---------- Previous update was at 12:40 ----------
And yes, you could use
sudo /home/user/public/usbreset /dev/bus/usb/001/$(lsusb | grep Webcam | cut -c16-18)
Backticks are deprecated and should be replaced by $( ... ) for command substitution.