You are not logged in.

#1 2016-07-28 11:30:50

FlowIt
Member
Registered: 2014-10-25
Posts: 239

Using rm !(file) in package function

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

#2 2016-07-28 12:08:24

xduugu
Member
Registered: 2008-10-16
Posts: 292

Re: Using rm !(file) in package function

According to bash's manpage, you habe to enable the extglob option.

Offline

#3 2016-07-28 12:15:11

FlowIt
Member
Registered: 2014-10-25
Posts: 239

Re: Using rm !(file) in package function

I know, and it is enabled. rm !(something) works in my terminal but not in the package function.

Offline

#4 2016-07-28 12:26:04

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Using rm !(file) in package function

How about using pacmans NoExtract directive?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#5 2016-07-28 12:28:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,524
Website

Re: Using rm !(file) in package function

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

#6 2016-07-28 12:31:14

FlowIt
Member
Registered: 2014-10-25
Posts: 239

Re: Using rm !(file) in package function

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

#7 2016-07-28 12:39:34

FlowIt
Member
Registered: 2014-10-25
Posts: 239

Re: Using rm !(file) in package function

Trilby wrote:

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

#8 2016-07-28 12:58:09

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,524
Website

Re: Using rm !(file) in package function

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

#9 2016-07-28 14:19:24

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,412
Website

Re: Using rm !(file) in package function

PKGBUILD(5) wrote:

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

#10 2016-07-28 14:19:24

FlowIt
Member
Registered: 2014-10-25
Posts: 239

Re: Using rm !(file) in package function

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

#11 2016-07-28 14:40:49

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,550

Re: Using rm !(file) in package function

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

#12 2016-07-28 14:45:40

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,524
Website

Re: Using rm !(file) in package function

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

#13 2016-07-28 14:47:48

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,550

Re: Using rm !(file) in package function

Right, I'm reinforcing it because his last post indicates that he doesn't get it when he talks about switching shells.

Offline

#14 2016-07-28 15:07:15

FlowIt
Member
Registered: 2014-10-25
Posts: 239

Re: Using rm !(file) in package function

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

#15 2016-07-28 15:08:29

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,524
Website

Re: Using rm !(file) in package function

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

#16 2016-07-28 15:16:39

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,784

Re: Using rm !(file) in package function

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

#17 2016-07-28 15:56:42

Awebb
Member
Registered: 2010-05-06
Posts: 6,286

Re: Using rm !(file) in package function

ewaller wrote:

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

#18 2016-07-28 16:03:17

FlowIt
Member
Registered: 2014-10-25
Posts: 239

Re: Using rm !(file) in package function

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

#19 2016-07-28 16:31:01

Awebb
Member
Registered: 2010-05-06
Posts: 6,286

Re: Using rm !(file) in package function

FlowIt wrote:

That's actually a link that should be found more often when searching for bash stuff!

Offline

Board footer

Powered by FluxBB