You are not logged in.

#1 2026-03-11 10:56:28

LinuxLover471
Member
From: Asia, India
Registered: 2025-02-23
Posts: 172

[SOLVED] Formatting: $pkgname or ${pkgname} when using variables?

Hi!

I wanted to know whether one should use `${pkgname}` or `$pkgname`, or is it just a preference.

Though which would be more ideal? I think the former? I think using it improves readability, but overusing it makes the PKGBUILD overall more bloated.

What are your thoughts?

Thanks!

Last edited by LinuxLover471 (2026-03-23 04:05:53)


--- asyync1024

Offline

#2 2026-03-11 12:02:28

5hridhyan
Member
From: Asia
Registered: 2025-12-25
Posts: 565

Re: [SOLVED] Formatting: $pkgname or ${pkgname} when using variables?

I guess, $pkgname for the sake of cleanliness, use ${pkgname} when you’re appending strings directly to the variable where it might get confusing...
No need to over-engineer it! smile


-----------

Offline

#3 2026-03-11 19:51:45

Muflone
Package Maintainer (PM)
From: Italy
Registered: 2013-10-08
Posts: 142
Website

Re: [SOLVED] Formatting: $pkgname or ${pkgname} when using variables?

There are situations where $variable might cause side effects like concatenating with other letters

At the opposite, using ${variable} you don't have such effects, therefore you don't have to worry about how you use your variables

For me there is only ${variable} because security beats uncertainty

Offline

#4 2026-03-12 08:51:04

LinuxLover471
Member
From: Asia, India
Registered: 2025-02-23
Posts: 172

Re: [SOLVED] Formatting: $pkgname or ${pkgname} when using variables?

Mufflone wrote:

There are situations where $variable might cause side effects like concatenating with other letters

Can you please elaborate on what can be the side effects? I would love to know how big of a problem can such a small change cause.
Thanks!


--- asyync1024

Offline

#5 2026-03-12 09:10:09

mithrial
Member
Registered: 2017-03-05
Posts: 149

Re: [SOLVED] Formatting: $pkgname or ${pkgname} when using variables?

If you have your variable $var and you want to concatenate this with another string:

var="asdf"
echo "$vartest"  # <-- breaks
echo "${var}test"

This example is obvious but you might have addititional information which might be confusing to the reader:

var="asdf"
echo "$var-v2"

As a bash-enthusiast, you know that the hyphen will be used literally, but it might lead to confusion. Is it the variable "var-v2" or not?

If you want to act on the content in bash, you must use the curly braces. For example, lowercase a string with "${var,,}". Using it everywhere will give it consistency.

Offline

#6 2026-03-23 04:08:09

LinuxLover471
Member
From: Asia, India
Registered: 2025-02-23
Posts: 172

Re: [SOLVED] Formatting: $pkgname or ${pkgname} when using variables?

Thanks to all of you for your respective insights!
I have decided to use ${var} only when using url's as they generally are quite hard to read, others aren't that hard.
Overusing ${var} can make a PKGBUILD bloated.

I have marked this post as SOLVED.

Last edited by LinuxLover471 (2026-03-29 07:17:08)


--- asyync1024

Offline

Board footer

Powered by FluxBB