Ask Your Question
0

Removing files in Sage shell using pattern matching

asked 2018-03-03 23:29:45 +0100

ninho gravatar image

updated 2018-03-03 23:30:00 +0100

I have a Sage project with includes some files ending in .sage and some ending in .py. So, I have also created a Makefile to preparse the Sage files, and inside my Makefile I have a clean command, which I want to delete all the files generated after the build process, but keep my own .py files. Therefore, I wrote something like this inside my Makefile:

clean:
    shopt -s extglob; 
    rm !(logger.py|utils.py|*.sage)

So, simply, when someone calls make clean I want it to delete all the .py and .pyc files generated after the make process, but keep the two .py files that are written by myself, and also keep all the Sage files. The problem is that it executes the first statement is executed successfully and it activates extended pattern matching. But then, the second state fails at (, it says that it got an unexpected character. To my knowledge, once the extended pattern matching is activated the above shown remove command should work. Any ideas what the problem might be and how to achieve what I want?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-03-04 12:49:16 +0100

tmonteil gravatar image

You can replace the two lines with a find command:

clean:
    find -type f ! -name logger.py ! -name utils.py ! -name "*.sage" -exec ls {} \;

Note that it will also look at the subdirectories. Once you are happy with that, you can replace ls with rm.

edit flag offensive delete link more

Comments

Thanks, this seems to work nicely!

ninho gravatar imageninho ( 2018-03-04 14:42:10 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-03-03 23:29:45 +0100

Seen: 318 times

Last updated: Mar 04 '18