You are not logged in.

#1 2022-11-01 20:33:36

Lancia
Member
Registered: 2022-11-01
Posts: 1

Storing the result of parameter expansion in a variable?

Hello everyone.

So I use parameter expansions in my VCS PKGBUILDs to get the name of the package without the VCS suffix ( e.g removing the "-git" suffix ) and use it for variables like provides and conflicts like this:

pkgname='pkg-git'
...
provides=("${pkgname%-*}")
conflicts=("${pkgname%-*}")

This is so I don't have to manually put them in those variables and risk making a mistake or typo, and also for convenience.

What I wanted to ask: should I store the result of the parameter expansion in a separate variable and use it where needed instead of computing it each time?

Now I am fully aware that the Arch Package Guidelines heavily advocates against defining new variables unless absolutely necessary, but I also want to be a little bit more efficient by reducing repetitive computation.

I know in the grand scheme of things it doesn't matter that much, however I would like to keep my PKGBUILDs in a high quality state and would certainly love to hear other more experienced peoples' opinions.

Offline

#2 2022-11-02 14:57:43

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 10,490

Re: Storing the result of parameter expansion in a variable?

Personally I hate the % method and feel it obscures what is meant.

In my opinion every PKGBUILD is unique and should be customized.
I'm much more likely to type out such values manually or if it's needed multiple times, prepend the varname with _ and use that instead of the % method.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

Board footer

Powered by FluxBB