#mawk

Gea-Suan Lingslin@abpe.org
2024-12-17

把 APT 的 Legacy Format 轉成 DEB822

機器升級到 Ubuntu 24.04 後,/etc/apt 下面的預設格式都變成 DEB822 格式了,看起來在「[Spec] APT deb822 sources by default」這邊有討論。

舊有的格式還是會吃,但總是想翻掉,我依照我有遇到的 case (但不是所有 legacy format 的 case) 用 AWK 一行轉完:

gawk '{if ($1 ~ /^deb/) {prin

blog.gslin.org/archives/2024/1

#Computer #Linux #Murmuring #OS #Programming #Software #apt #awk #deb822 #debian #format #gawk #legacy #linux #mawk #ubuntu

genstar.serviceGenstar@meow.social
2023-04-07

Can someone tell the asshole at invisible-island.net to unblock my country?

I'm not sure why would you need to block Argentina in the first place, I'm trying to download the source to mawk here.

#InvisibleIsland #InvisibleIslandNet #Sucuri #SucuriFirewall #GeoBlocking #GeoBlock #GeoBlocked #mawk #awk #Argentina #FLOSS #FOSS #OSS #SoftwareLibre

So I asked myself, "Can I get away with calling srand() once instead of twice?"

TLDR: You can, dependent on implementation, but you shouldn't. srand() needs to run at least once in order for the second call to srand() to be guaranteed a seed (our timestamp) to return.

--- Of course there's a long answer. ---

It appears that just printing srand's return value is enough in #mawk, but that's due to a compile-time and run-time configuration that might not be present in another mawk installation or even another awk implementation. (automatically calling srand() on mawk startup)

To be most portable, srand() needs to be called more than once to get a timestamp. The seed value isn't guaranteed to be there unless you call srand() at least once. Since srand() returns the *last* seed instead of what it's setting it to, mawk's use of srand() on startup is fine. It adds convenience to fetching (pseudo-)random numbers right off the bat. However, it's still good practice to call srand() just before you need it, to ensure the timestamp you're returning isn't stale. If you didn't do this, long-running mawk scripts would report the timestamp of when mawk was first started instead of the current timestamp.

C appears to initialize the srand seed value to 1, so mawk can be told to mimic this behavior (if the functionality was baked in at compile-time, like it is in Adélie Linux):

mawk -Wrandom=1 'BEGIN { print srand() }'
(empty line)

Re-add the srand() call before the print statement and all is good again. You can remove the -W flag again, too, returning to the original line:

mawk 'BEGIN { srand(); print srand()}'

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst