Skip to main content
deleted 3 characters in body; edited title
Source Link
muru
  • 78.1k
  • 16
  • 213
  • 319

bash scripting: How do I perform rm -v !(*.yaml) in a bash script?

In the script it reads: rm -v !\(*.yaml\) ; this produces rm: cannot remove '!(*.yaml)': No such file or directory, but works fine in the command line. Have tried escaping in various ways:

`\rm -v !\(\**.yaml\)` ;\
`

this produces

rm: cannot remove '!\(*.yaml\"\)`
"\!\(\*.yaml\yaml)"': No such file or directory

but works fine in the command line. Have tried escaping in various ways:

'\!\(\*.yaml\)'
`\!\(\*.yaml\)`
`!\(*.yaml\"\)`
"\!\(\*.yaml\)"

Can't seem to figure out the appropriate escape sequence, I simply don't understand. Escaping the brackets was my first step. Then trying to escape the !, then the *. Also tried no escaping, using back-ticks but I got the error "rm missing operand". Im a little stumped. Have been at it for about an hour - just "rm everything not yaml"... Can anyone perhaps spot the error/suggest a fix?

Many thanks,

P.S: HaveI have also tried #!/bin/sh and #!/bin/bash. Thought it would maybe have some effect.

bash scripting: How do I perform rm -v !(*.yaml) in a bash script?

In the script it reads: rm -v !\(*.yaml\) ; this produces rm: cannot remove '!(*.yaml)': No such file or directory, but works fine in the command line. Have tried escaping in various ways:

`\!\(\*.yaml\)`
`!\(*.yaml\"\)`
"\!\(\*.yaml\)"

Can't seem to figure out the appropriate escape sequence, I simply don't understand. Escaping the brackets was my first step. Then trying to escape the !, then the *. Also tried no escaping, using back-ticks but I got the error "rm missing operand". Im a little stumped. Have been at it for about an hour - just "rm everything not yaml"... Can anyone perhaps spot the error/suggest a fix?

Many thanks,

P.S: Have also tried #!/bin/sh and #!/bin/bash. Thought it would maybe have some effect.

How do I perform rm -v !(*.yaml) in a bash script?

In the script it reads:

rm -v !\(*.yaml\) ;\

this produces

rm: cannot remove '!(*.yaml)': No such file or directory

but works fine in the command line. Have tried escaping in various ways:

'\!\(\*.yaml\)'
`\!\(\*.yaml\)`
`!\(*.yaml\"\)`
"\!\(\*.yaml\)"

Can't seem to figure out the appropriate escape sequence, I simply don't understand. Escaping the brackets was my first step. Then trying to escape the !, then the *. Also tried no escaping, using back-ticks but I got the error "rm missing operand". Im a little stumped. Have been at it for about an hour - just "rm everything not yaml"... Can anyone perhaps spot the error/suggest a fix?

I have also tried #!/bin/sh and #!/bin/bash. Thought it would maybe have some effect.

Became Hot Network Question
Source Link

bash scripting: How do I perform rm -v !(*.yaml) in a bash script?

In the script it reads: rm -v !\(*.yaml\) ; this produces rm: cannot remove '!(*.yaml)': No such file or directory, but works fine in the command line. Have tried escaping in various ways:

`\!\(\*.yaml\)`
`!\(*.yaml\"\)`
"\!\(\*.yaml\)"

Can't seem to figure out the appropriate escape sequence, I simply don't understand. Escaping the brackets was my first step. Then trying to escape the !, then the *. Also tried no escaping, using back-ticks but I got the error "rm missing operand". Im a little stumped. Have been at it for about an hour - just "rm everything not yaml"... Can anyone perhaps spot the error/suggest a fix?

Many thanks,

P.S: Have also tried #!/bin/sh and #!/bin/bash. Thought it would maybe have some effect.