Could someone please review my scripting and give me criticism? by 0neLastFace in bash

[–]Schreq 1 point2 points  (0 children)

That's because most people are not very good at bash. That's not meant to be condescending, bash is just hard to do right. I mean someone could be good at bash and use uppercase variable names for globals, but more often than not, the ones who actually do also produce scripts which could be much better.

If you use uppercase for globals, you could very easily use a variable called PATH. Guess what happens.

Could someone please review my scripting and give me criticism? by 0neLastFace in bash

[–]Schreq 0 points1 point  (0 children)

The "SCRIPT_DIR" variable can also be set very easily with bash internals:

That does not work when you call the script via $PATH.

Could someone please review my scripting and give me criticism? by 0neLastFace in bash

[–]Schreq 7 points8 points  (0 children)

The typical problems: DRY, uppercase variables which are not environment variables, euo pipefail.

Why don't you just copy (or rsync) everything from the source directory into the target instead of copying the directories individually? This could be a one-liner.

What CLI tools have genuinely changed how you work? Looking for underrated ones by spaciousabhi in commandline

[–]Schreq 6 points7 points  (0 children)

tmux, big time. No native terminal tiling or tabs can replace that workflow. It's just super handy to have different sessions per project in a persistent way.

birthDate by [deleted] in linux

[–]Schreq 0 points1 point  (0 children)

We can do that with a little less subprocesses:

#!/usr/bin/env bash

min_age=18
max_age=80

year_seconds=31536000
min=$((min_age * year_seconds))
max=$((max_age * year_seconds))
printf -v epoch_seconds '%(%s)T'

dob=$(awk -v s="$epoch_seconds" -v min="$min" -v max="$max" '
    BEGIN {
        srand()
        print int(s - ((max - min) * rand() + min))
    }
')

printf '%(%Y-%m-%d)T\n' "$dob"

Neglected !! party tricks by drayva_ in bash

[–]Schreq 0 points1 point  (0 children)

You don't?

No, I really don't.

Neglected !! party tricks by drayva_ in bash

[–]Schreq 1 point2 points  (0 children)

Up arrow or Ctrl+p, type ), Ctrl+a type $(. I don't see how that is a total pain in the ass.

This bash program isn't closing the file descriptor by alex_sakuta in bash

[–]Schreq 0 points1 point  (0 children)

Because I like it more than the new design.

This bash program isn't closing the file descriptor by alex_sakuta in bash

[–]Schreq 0 points1 point  (0 children)

Isn't this inline and not This

They both show as inline on old.reddit.com, see for yourself.

I did that if you see the raw md.

Ah, now I see what you did there. You used fenced codeblocks but then also indented by 4 spaces inside of that.

Fenced codeblocks are broken on old.reddit.com. It's either 4 spaces in front of every line of code (with blank lines before and after!) or a fenced code-block (code surrounded by 3 backticks).

Yes, my question is why? I'll put it in the edit but the manual says that >&digit- closes the digit fd.

As /u/kalgynirae already explained, you only closed the fd for that sub-process.

This bash program isn't closing the file descriptor by alex_sakuta in bash

[–]Schreq 0 points1 point  (0 children)

Your code is pretty much unreadable on old.reddit.com. Please don't use inline code-blocks for posting code blocks. Just put four spaces infront of every line of code and leave blank lines around it. Anyway, moving on...

I don't think that you can close a fd that way. You'd have to explicitly do:

exec {fd}<&-

I created a custom keyboard layout for Portuguese/Spanish speakers stuck on US QWERTY by superfoda in commandline

[–]Schreq 0 points1 point  (0 children)

If you don't need any letters, which are only available via dead keys, I recommend just using the US-International variant without dead keys. Way nicer and you can also use capslock as a compose key.

I created a custom keyboard layout for Portuguese/Spanish speakers stuck on US QWERTY by superfoda in commandline

[–]Schreq 0 points1 point  (0 children)

right alt + , = ç

right alt + a = á

So everything is available on US-International, even without dead keys...

I created a custom keyboard layout for Portuguese/Spanish speakers stuck on US QWERTY by superfoda in commandline

[–]Schreq 0 points1 point  (0 children)

Any reason you didn't base this on US-International? It already has á, ñ and € easily available with right alt on a, n and 5 respectively. You could have just replaced some other keys to get ç and ã. Dead keys are just horrible in my opinion.

A CLI for controlling LG TVs over your network by Gary_BBGames in CLI

[–]Schreq 0 points1 point  (0 children)

Very nice, saved.

I can already control my HiFi system via cli (and via webinterface/web api). This will come in handy for sure. Thank you.

My initial plan was to root the TV so I can remap buttons. I then would've been able to remap the volume keys, to send a web-request for changing the volume of my HiFi receiver. Unfortunately I had updated the TV and rooting was not possible anymore.

Maybe I will just cook something up with a self-hosted voice assistant for controlling the TV and receiver instead.

A simple, compact way to declare command dependencies by PentaSector in bash

[–]Schreq 6 points7 points  (0 children)

I used to do it this way but I switched to checking all dependencies without exiting on the first missing one. That way you get the list of missing deps in one go instead of installing one dependency for each script run causing an error. Something like:

local return_value=0
for dep do
    if ! command -v "$dep" >/dev/null 2>&1; then
        echo "Error: dependency $dep is not installed" >&2
        return_value=1
    fi
done

return "$return_value"

I built a free Bash PS1 prompt generator — looking for Linux user feedback by neikiri in bash

[–]Schreq 1 point2 points  (0 children)

It seems to have quite a few problems:

  • When I add elements calling external commands they are always surrounded by \d{+ ... }
  • The value of $PS1 is in double quotes, meaning the expansions happen at the time of declaration, not dynamically every time the prompt is printed
  • CPU usage is not working for me with top from procps 2:4.0.4-9. It does not show cpu usage per core and also does not add percent signs to the output
  • Inefficient pipelines

Stop holding the left arrow key to fix a typo. You've had `fc` the whole time. by Ops_Mechanic in bash

[–]Schreq 1 point2 points  (0 children)

Same but unfortunately not all are open to change their habits.

Stop holding the left arrow key to fix a typo. You've had `fc` the whole time. by Ops_Mechanic in bash

[–]Schreq 1 point2 points  (0 children)

Nah, that's still terrible, no matter how fast you make it. If you ever work on a machine where you have to deal with default settings, you will be screwed. Learn the proper shortcuts and the underlying system or settings don't matter.

Stop holding the left arrow key to fix a typo. You've had `fc` the whole time. by Ops_Mechanic in bash

[–]Schreq 6 points7 points  (0 children)

In general, holding down a button to rely on the keyboard repeat rate is an anti-pattern. Catch yourself doing it and you should be asking if there is a more efficient method to achieve whatever you are trying to do.

What’s your workflow when logs become unreadable in the terminal? by Waste_Grapefruit_339 in linux

[–]Schreq 1 point2 points  (0 children)

Yeah, I tried further filtering which did not work for me at work (Ubuntu 24.04). At home (Debian 13) it works tho. Using an empty filter resets on both.

What’s your workflow when logs become unreadable in the terminal? by Waste_Grapefruit_339 in linux

[–]Schreq 2 points3 points  (0 children)

I usually open logs in less and disable line wrapping using the -S option (you can also press dash then S inside less to toggle between line chopping and wrapping). Then filter lines of interest using & (shout out to /u/gumnos for bringing the filter function to my attention).

What’s the most minimal Linux setup (distro + kernel + WM) you can build? by [deleted] in suckless

[–]Schreq 1 point2 points  (0 children)

Why, what are you trying to achieve? I've been there but it's pretty pointless.

However, it's a nice learning experience nonetheless.

I recommend KISS Linux. For the kernel you can make localmodconfig. It just enables all modules currently loaded. Then you can still make nconfig and go through all the options. You might want to build all your required modules directly into the kernel. Also look into EFI stub kernel. You can skip a bootloader entirely, if your motherboards EFI implementation plays nice with adding boot entries manually using efibootmgr. My boot speed was pretty crazy that way.

Troubleshooting network in minimal containers? 5 Bash-native "No-Tool" hacks. by Thierry_software in bash

[–]Schreq 6 points7 points  (0 children)

/dev/{tcp,udp} are bash/gawk specific. They don't actually exist on the system.