I have a problem running a line of code in my Makefile that runs well in /bin/bash
. I know that Make runs in /bin/sh
so I have solved that problem with this guide by declaring to Make that I want it to run in Bash. However, even though I run Make in Bash I still cant get this line to work, even tough it works in Bash just fine.
Why does Bash throw an error when running rm -f !(2).txt
in the Makefile but not when executed out in its shell?
EDIT: I seek to delete all files with a certain file extension except one of those files. The command
rm -f !(2).txt
does just that in my bash terminal but not in Make.EDIT: When running
rm -f !(2).txt
"normally" in the terminal with Bash (terminal returnedbash
when issuing commandecho "$0"
) it works just fine but whey I run/bin/bash -c 'rm -f !(2).txt'
I get the same error as in the Makefile.
Makefile
all: clean
clean: SHELL:=/bin/bash
clean:
rm -f !(2).txt
Running command in Bash
$ ls
1.txt 2.txt 3.txt 4.txt Makefile # Directory has all text files
$ rm -f !(2).txt # Remove all text files but 2.txt
$ ls
2.txt Makefile # Only 2.txt is not removed
Running command in Bash through Makefile
$ ls # Directory has all text files
1.txt 2.txt 3.txt 4.txt Makefile
$ make clean # Running make
rm -f !(2).txt
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `rm -f !(2).txt'
make: *** [clean] Error 1