219
Subscribers
No data24 hours
+17 days
+530 days
Posts Archive
Repost from Zhovner Hub
ΠΡΠ΅ΠΌ Linux ΠΌΠ°ΡΡΠ΅ΡΠ° Π΄Π»Ρ Π½ΠΎΠ²ΠΎΠ³ΠΎ Flipper One
ΠΡ Π΄Π΅Π»Π°Π΅ΠΌ Π½ΠΎΠ²ΡΠΉ Flipper One β ΡΡΠΎ ARM-ΠΊΠΎΠΌΠΏΡΡΡΠ΅Ρ Π½Π° Linux Π½Π° Π±Π°Π·Π΅ ΠΏΡΠΎΡΠ΅ΡΡΠΎΡΠ° RK3576. ΠΡ Ρ
ΠΎΡΠΈΠΌ ΡΠ»Π΅ΠΏΠΈΡΡ Π΄Π»Ρ Π½Π΅Π³ΠΎ ΡΠ²ΠΎΠΉ ΠΊΠ°ΡΡΠΎΠΌΠ½ΡΠΉ Π΄ΠΈΡΡΡΠΈΠ±ΡΡΠΈΠ².
ΠΡ Π½Π΅ Ρ
ΠΎΡΠΈΠΌ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΡΡΡΠ°ΡΠ΅Π²ΡΠΈΠ΅ ΡΠΈΡΡΠ΅ΠΌΠ½Ρ ΠΎΠ±Π½ΠΎΠ²Π»Π΅Π½ΠΈΡ Π²ΡΠΎΠ΄Π΅ Debian APT.
ΠΠΎΡΠ΅ΠΌΡ ΠΊΠ»Π°ΡΡΠΈΡΠ΅ΡΠΊΠ°Ρ ΡΠΈΡΡΠ΅ΠΌΠ° ΠΎΠ±Π½ΠΎΠ²Π»Π΅Π½ΠΈΠΉ APT Π½Π°ΠΌ Π½Π΅ ΠΏΠΎΠ΄Ρ
ΠΎΠ΄ΠΈΡ:
β’ ΠΠ±Π½ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ Π»Π΅Π³ΠΊΠΎ ΠΌΠΎΠΆΠ΅Ρ ΡΠ»ΠΎΠΌΠ°ΡΡΡΡ Π½Π° ΡΠ΅ΡΠ΅Π΄ΠΈΠ½Π΅ ΠΈ ΡΠΈΡΡΠ΅ΠΌΠ° ΡΡΠ°Π½Π΅Ρ Π½Π΅ ΠΊΠΎΠ½ΡΠΈΡΡΠ΅Π½ΡΠ½Π°
β’ ΠΠ΅Π»ΡΠ·Ρ ΠΎΡΠΊΠ°ΡΠΈΡΡΡΡ ΠΊ ΠΏΡΠ΅Π΄ΡΠ΄ΡΡΠ΅ΠΉ Π²Π΅ΡΡΠΈΠΈ
β’ ΠΠ΅Π»ΡΠ·Ρ ΡΠ±ΡΠΎΡΠΈΡΡ Π½Π°ΡΡΡΠΎΠΉΠΊΠΈ Π² Π΄Π΅ΡΠΎΠ»ΡΠ½ΡΠ΅
ΠΠΎΡΡΠΎΠΌΡ ΠΌΡ ΠΈΡΠ΅ΠΌ ΡΠΏΠ΅ΡΠ° ΠΏΠΎ Linux Π΄ΠΈΡΡΡΠΈΠ±ΡΡΠΈΠ²Π°ΠΌ, ΠΊΠΎΡΠΎΡΡΠΉ ΡΠΏΡΠΎΠ΅ΠΊΡΠΈΡΡΠ΅Ρ Π΄ΠΈΡΡΡΠΈΠ±ΡΡΠΈΠ² Π΄Π»Ρ Flipper One Π½Π° ΠΎΡΠ½ΠΎΠ²Π΅ ΠΌΠΎΠ΄Π½ΠΎΠΉ ΠΌΠΎΠ΄Π΅Π»ΠΈ Ρ A/B-ΡΠ°Π·Π΄Π΅Π»Π°ΠΌΠΈ, read-only ΠΊΠΎΡΠ½Π΅Π²ΡΠΌ ΡΠ°Π·Π΄Π΅Π»ΠΎΠΌ ΠΈ Π°ΡΠΎΠΌΠ°ΡΠ½ΡΠΌΠΈ ΠΎΠ±Π½ΠΎΠ²Π»Π΅Π½ΠΈΡΠΌΠΈ.
Π₯ΠΎΡΠΈΠΌ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ Π½Π°ΡΠ°Π±ΠΎΡΠΊΠΈ ΡΡΡΠ΅ΡΡΠ²ΡΡΡΠΈΡ
ΠΏΡΠΎΠ΅ΠΊΡΠΎΠ², ΡΠΈΠΏΠ° SteamOS, OSTree, RAUC ΠΈ Ρ.Π΄.
ΠΠ»Ρ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»ΡΡΠΊΠΈΡ
ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΉ Ρ
ΠΎΡΠΈΠΌ ΠΏΠ°ΠΊΠ΅ΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ ΡΠΈΠΏΠ° β Flatpak, AppImage ΠΈΠ»ΠΈ Snap ΠΈΠ»ΠΈ ΠΏΠΎΠ΄ΠΎΠ±Π½ΠΎΠ³ΠΎ.
ΠΡΠ»ΠΈ Π²Ρ ΡΠΌΠ΅Π΅ΡΠ΅ ΡΠ°ΠΊΠΎΠ΅, ΠΏΡΠΈΡ
ΠΎΠ΄ΠΈΡΠ΅ ΠΊ Π½Π°ΠΌ β https://flipperdevices.com/jobs
More shell tricks: first class lists, jq, and the es shell
On the web: https://alurm.github.io/blog/2025-08-07-first-class-lists-in-shells.html
Preamble
It's not a secret that most common shells don't have first class lists.
Sure, you can pass a list to a program by passing each element in argv (e.g. with
"$@" or "${list_variable[@]}"), but what if you want to *return* a list?
There are a couple of options.
The challenge
As a more practical example of this, let's implement split-by-double-dash, a function (or a program) that would return two lists: args that come before -- and ones that come after. That's a common format used by command line utilities.
So, for example, split-by-double-dash a b c -- d e f should return the lists [a, b, c] and [d, e, f], *somehow*.
One possible use case for this would be a wrapper around a utility that accepts arguments in this form.
The quoting way with jq
Some utilities can return text quoted in the syntax of shell. For examples, getopt and jq can do that. getopt can indeed help us solve the problem of parsing cli options, but we'll focus on jq here.
> Side note: jq is an amazing utility (in fact, a programming language) that can manipulate structured data in all kinds of ways.
Here's an example:
jq -nr '["foo", "baz", "baz quux"] | @sh'
'foo' 'baz' 'baz quux'
We ask jq to turn a list into a string suitable for consumption with shell's eval. -n tells that there's no input to read, -r tells jq to output text, not JSON. So let's see how to use the output in the shell:
eval set -- "$(jq -nr '["foo", "bar", "baz quux"] | @sh')"
# Now, let's verify that arguments has been passed correctly, by printing each one on a separate line with printf.
printf 'arg: %s\n' "$@"
# Output:
# arg: foo
# arg: bar
# arg: baz quux
You might think: "wait, you can't use eval". But that's actually safe, since jq does the escaping for us. Actually, I don't think there's a way to do this without eval, since the list is dynamic and has to be interpreted by the shell.
In fact, lists can be nested, which is what we want, since we want to return two lists. The outputs gets a bit unwieldy at this point though:
jq -nr '[["foo", "bar"], ["baz", "baz quux"]] | map(@sh) | @sh'
# Output:
# ''\''foo'\'' '\''bar'\''' ''\''baz'\'' '\''baz quux'\'''
What happens with | map(@sh) | @sh is that we first apply quoting to each of the lists to get a list of strings, and then we quote *that*.
But, if we want to implement split-by-double-dash, we need a way to process the arguments passed to jq. Can we do this? Of course we can.
jq '$ARGS.positional' -n --args -- a b c
# Output: ["a", "b", "c"]
In fact, jq has much more (check out the manual), so I'll skip right ahead to the solution. We'll use the #!/usr/bin/env shebang and we'll pass -f to jq to make this a proper script:
#!/usr/bin/env -S jq -nrf --args --
# Usage: eval set -- "$(split-by-double-dash ...)"
# Or, in Bash: eval array=("$(split-by-double-dash ...)")
$ARGS.positional |
reduce .[] as $arg (
{
before: [],
after: [],
found: false,
};
if .["found"] then
. | .after += [$arg]
elif $arg == "--" then
. | .found = true
else
. | .before += [$arg]
end
) |
{ before, after } |
map(@sh) |
@sh
Here's how to use this (in Bash, but you can use this in sh as well):
eval array=("$(./split-by-double-dash a b c -- d e f)")
eval before=("${array[0]}")
eval after=("${array[1]}")
# Example:
printf '%s\n' "${before[@]}"
# Output:
# a
# b
# c
(Continued in the comments...)ΠΡΠΎΠ²ΡΠ» Π»Π΅ΠΊΡΠΈΡ ΠΏΡΠΎ Nix Π² @f0rthsp4ce. Nix ΡΡΠΎ ΡΠ°ΠΊΠΎΠΉ ΡΠ·ΡΠΊ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΡ/ΠΏΠ°ΠΊΠ΅ΡΠ½ΡΠΉ ΠΌΠ΅Π½Π΅Π΄ΠΆΠ΅Ρ/ΡΠΏΠΎΡΠΎΠ± ΠΎΠΏΠΈΡΡΠ²Π°ΡΡ ΠΎΠΊΡΡΠΆΠ΅Π½ΠΈΡ ΡΠ°Π·ΡΠ°Π±ΠΎΡΠΊΠΈ.
ΠΠΎ-ΡΡΡΡΠΊΠΈ.
https://youtube.com/watch?v=noEbul27dHE
