You are not logged in.
I have a package that ships with tons of themes that I will never use. So I tried to modify the PKGBUILD and added
cd "$pkgdir/usr/share/app/themes"
rm !(default.theme)
In this case I get
syntax error near unexpected token `('
So I tried to escape the parentheses with a backslash. In this case the PKGBUILD runs, but the themes are not deleted.
A solution that would work is
ls | grep -v default.theme | xargs rm
but this not as readable as rm !(default.theme). So is there a way to get the first one working?
Last edited by FlowIt (2016-07-28 11:31:24)
Offline
According to bash's manpage, you habe to enable the extglob option.
Offline
I know, and it is enabled. rm !(something) works in my terminal but not in the package function.
Offline
Offline
Have you enabled it in the package function?
Why not use a more portable approach:
find -type f ! -name default.theme -exec rm '{}' +
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
This would be another option, but maybe in the future I have a split package where I want to remove all files but one for package a and remove this file in package b. This would not work with NoExtract.
Last edited by FlowIt (2016-07-28 12:31:30)
Offline
Have you enabled it in the package function?
Do you mean via shopt -s extglob? Yes, this does not change anything. Maybe I do something wrong with escaping?
Is there a portability difference between find exec and xargs? I chose
ls | grep -v default.theme | xargs rm
because for me it is easier to read. But both work fine.
Offline
shopt may not work in a PKGBUILD because of other limitations on the shell calling those functions.
Find is much safer than parsing the output of `ls`. But actually my command could be simplified to:
find -type f ! -name default.theme -delete
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
noextract (array)
An array of file names corresponding to those from the source array. Files listed here will not be extracted with the rest of the source files.
This is useful for packages that use compressed data directly.
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
So how do we solve this? Better not using bashisms and just use find? The longer I think about it it's probably the best solution, mainly because I could switch the shell at any time. And in terms of readability I guess after working more with find and other commands they will look as simple as rm !(something).
Offline
Your shell has absolutely no bearing on this. Pacman invokes bash itself, so what shell you're running or what options you're running it with are meaningless.
Offline
Scimmia, this is what I was commenting/asking about. Running `shopt -s extglob` outside the PKGBUILD is irrelevant, but putting that in the package function before the rm command might work - though I still don't think that's a good approach.
EDIT: ah, I failed to fully digest the post this was in reply to.
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Right, I'm reinforcing it because his last post indicates that he doesn't get it when he talks about switching shells.
Offline
I get it now. That pacman invokes a new shell was clear from the beginning, but I wasn't sure if pacman uses bash or the user's interactive shell (and in this case it would be better to write POSIX-compliant PKGBUILDs). But back to topic: Are there any arguments which speak against the use of rm !(something), apart from the fact that I couldn't get it to work?
Offline
Not that I know of - but if it's not working, that seems to be a pretty compelling argument against it.
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
As a casual observer -- and one who does not write much in Bash -- I would have had no clue what rm !(default.theme) would do. Not something I relish when auditing a random PKGBUILD before running it.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
As a casual observer -- and one who does not write much in Bash -- I would have had no clue what rm !(default.theme) would do. Not something I relish when auditing a random PKGBUILD before running it.
It's also something I don't want to feed a search engine with. Can anybody point at the right piece of a bash doc, for the casual observer?
EDIT: Okay, "extglob", it's a not. That's somewhat cryptic, because extglob is not the default and !expression usually means something else.
Last edited by Awebb (2016-07-28 15:59:49)
Offline
Here you go: https://www.gnu.org/software/bash/manua … n-Matching
Edit: Oh too late
Last edited by FlowIt (2016-07-28 16:03:48)
Offline
Here you go: https://www.gnu.org/software/bash/manua … n-Matching
Edit: Oh too late
That's actually a link that should be found more often when searching for bash stuff!
Offline