'How should I use extglob in Python fabric?
I am trying to use fabric (v2.6) to run some commands that make use of bash's extglob and dotglob.
When I run:
c.run(f"shopt -s extglob dotglob && rm -Rf {project_path}* !(.|..|.venv) && shopt -u extglob dotglob")
I get this error:
`bash: -c: line 0: syntax error near unexpected token `('`
I am using the &&
because I found doing shopt -s extglob dotglob
in a separate run call doesn't persist for the subsequent run calls. I'm pretty sure using &&
is enabling extglob and dotglob because when I do this:
`c.run("shopt -s extglob dotglob && shopt")`
It prints out the list of options and extglob and dotglob are both enabled.
Where am I going wrong here?
Solution 1:[1]
From the bash wiki:
extglob
changes the way certain characters are parsed. It is necessary to have a newline (not just a semicolon) betweenshopt -s extglob
and any subsequent commands to use it.
So you have to change your python code appropriately so that a newline is used instead of &&
.
Or just do what the bash invocation does directly in python.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Shawn |