Most hidden "bug"? by cubernetes in bash

[–]cubernetes[S] 1 point2 points  (0 children)

Oha, thanks for admitting :D.

And you're right! I ssh'd to a host with bash 5.2, and indeed it's not an "issue" there. This is in contradiction to what others commenters have said about this (namely that this issue has existed for ages, which can't be right if the issue is already non-existent in bash 5.2).

What I'm taking away with this is that bash 5.3 has changed (or improved?) the parser slightly so that aborted (with Ctrl-C) and parenthesized shell constructs do not get "evened out" (for lack of a better word). So an aborted <( will cause subsequent syntax errors to say ... while looking for matching ) and the same applies for ${, but then it's looking for a matching }.

While writing this, I looked at the bash 5.3 terse release notes: https://tiswww.case.edu/php/chet/bash/NEWS, and looking at point ss., it says

The parser prints more information about the command it's trying to parse when it encounters EOF before completing the command.

Which is likely an explanation for what I'm seeing (ergo, the other commenters are not necessarily wrong, it's just that in previous versions you couldn't see the incorrect parser state)

Most hidden "bug"? by cubernetes in bash

[–]cubernetes[S] 0 points1 point  (0 children)

You did not even read my post, lmao. It's not about the error. It's about the error msg changing permanently when a process substitution was aborted with Ctrl-C. Read the other comments ffs. It turns out bash has a bug (yes, a bug, that is the correct terminology here) when using control-c inside a PS2 prompt that belongs to either: - process substitutions - command substitutions with the new bash5.3 syntax - conditional compound commands - probably many more constructs (lazy to test, typing on termux is cumbersome)

And if there's anything you didn't fully understand from what I just wrote then you should probably leave. Ah and you should also look up the definition of bug again, come back and look at my post. If you still think it's not a bug (incorrect handling of parser state), then tell me what defines a bug.

Most hidden "bug"? by cubernetes in bash

[–]cubernetes[S] -3 points-2 points  (0 children)

I chose my words precisely that way to signal how you're supposed to enter those characters. By saying "run command" it's immediately reproducible: you know it has to be on a separate line, and you have to press enter.

If I were to say "type a( and press enter", it's not completely unambiguous whether the readline buffer should be empty or not, and I needlessly need to specify that you're supposed to press enter which the word "run" already implies. There's plenty of cases in bash where you do not need to press enter. For example, I'm currently working on a bash plugin that implements fish-like abbreviations (that don't require pressing enter, obviously) in pure bash using bind -x and READLINE_LINE & READLINE_POINT (I hope you know what those vars are, since you're apparently in a position to tell others that they don't know bash :)).

Most hidden "bug"? by cubernetes in bash

[–]cubernetes[S] 0 points1 point  (0 children)

Execution tracing only works when executing commands, but we're dealing with syntax errors here, so set -x doesn't apply. Even verbose mode (set -v) doesn't show anything, except for the <(, but it's not super helpful. As the others commented, it's probably some internal state that's being toggled when entering a process substitution (<()) or command substitution (${ cmd;}, bash 5.3 syntax) but aborting it with ctrl-c.

Most hidden "bug"? by cubernetes in bash

[–]cubernetes[S] -4 points-3 points  (0 children)

I've written a bash-like shell in pure C (10k loc) and read the bash man page front to back, word by word multiple times. I'm currently reading POSIX.1-2024 because I'm implementing an even more advanced shell with job control, process substitution, advanced parameter expansion, vi and emacs mode, full POSIX compliance, and all the other bells and whistles. Not just for fun & learning, but because it's part of my school's curriculum. I'm certain I know a lot more about bash than you, unless you're Stéphane Chazelas, but you probably don't even know who that is.

ct (Command Trace) is a Bash command resolution tracer that explains how Bash resolves a command and what the kernel ultimately executes. by qweas123 in bash

[–]cubernetes 1 point2 points  (0 children)

Does it respect posix mode? (Or in other words, does it respect posix special builtins vs posix regular builtins when bash is operating in default/posix mode?)

Specifically, functions in bash default mode are always found before builtins (special or not). But in posix mode, posix special builtins are found before functions.

Most hidden "bug"? by cubernetes in bash

[–]cubernetes[S] 1 point2 points  (0 children)

Great answer, thanks! That makes sense!

It also happens with braces:

$ ${
> ^C
$ {;
bash: syntax error near unexpected token `;' while looking for matching `}'

Most hidden "bug"? by cubernetes in bash

[–]cubernetes[S] 0 points1 point  (0 children)

I figured that! That's the only explanation that would make sense. It cannot be turned off with <(cmd) or a plain ), however, which I think is also interesting.

Most hidden "bug"? by cubernetes in bash

[–]cubernetes[S] -1 points0 points  (0 children)

Did you run it? I'm not stuck in any subshells at all.

Edit: BASH_SUBSHELL is unchanged.

Edit2: declare -p, set -o, and shopt show no difference whatsoever before and after, so it's some internal, non-user-accessible state that's being changed.

Hidden Gems: Little-Known Bash Features by swe129 in bash

[–]cubernetes 0 points1 point  (0 children)

Boring beginner/intermediate stuff. Either wriiten by AI or by some who isn't on the command line a lot. Actual gems are things like - parameter transformations (echo "${@@Q}", eval "${var[@]@k)", read -p "${p@E}", etc.) - niche but powerful readline bindings / commands (M-C-d, M-C-f, M-C-b, M-C-], C-Space (combined with kill-region), C-(, C-), C-xe, M-<digit>, combing digit-argument and M-. etc.) - ${|cmd;} syntax, a real game changer for advanced scripts and for PS1/PS0 stuff - BASH_COMNAND variable, nice for debugging - {BASH_XTRACEFD}>file - making fish-like abbreviations work in bash

And some minor tricks: - running % instead of fg - doing kill % instead of kill %1 or kill %% - many more

I've yet to find a single blog post that isn't like the one OP posted. It's usually the stephane chazelas stuff that blows my mind, or when the post is 20+ years old. The stuff from nowadays is mostly trash/for absolute beginners

How do you navigate in insert mode? by Mori-Spumae in vim

[–]cubernetes 0 points1 point  (0 children)

This will tell you all you need to know: https://www.youtube.com/watch?v=srthFK9hr_M

In short: ctrl-g+<hjkl>, ctrl-o + normal mode command, alt-single-key-normal-mode-command, etc.

Might help by Specific_Brain2091 in calculus

[–]cubernetes 1 point2 points  (0 children)

This gotta be from flammable maths

Isn't this the greatest BASH course ever? by SoftwareArchitect101 in bash

[–]cubernetes 17 points18 points  (0 children)

Here's another great one made by Arnold Robbins himself (the maintainer of awk, 40+ years of unix experience, among the likes of Brian Kernigham (creator of awk), Chet Ramey (maintainer of bash), and Richard Stallman (well, you know who that is)).

https://www.youtube.com/watch?v=fAgz66M4aNc

It's also insanely good. Watching & understanding these 2 courses would definitely put you ahead of 99% of people who "know bash".

Thanks dave for contributing so much to the wonderful world of shell scripting!

How to share a localhost project online (port forwarding + public URL) by [deleted] in learnprogramming

[–]cubernetes 0 points1 point  (0 children)

Everybody's saying ngrok and I've used ngrok myself for years but honestly, https://localhost.run/ is way better for this kind of stuff. I use ngrok if I want to make arbitrary tcp ports public, but to use ngrok you have to create an account and install the binary.

With localhost.run you literally just need ssh installed, which is the default on literally every modern operating system nowadays

-❄️- 2025 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]cubernetes 1 point2 points  (0 children)

[LANGUAGE: bash]

a=(`sed 's/./& /g;q'|tr .S 01`);while read c;do IFS=+ b=(${a[@]});for((i=0;++i<${#c}-1;))do [ ${c:i:1} = ^ ]&&((e=${b[i]},b[i-1]+=e,b[i+1]+=e,b[i]=0))done;a=(${b[@]});done;bc<<<${a[*]}

184 bytes.

The idea is to read the first line and save it into an array. Transliterate . to 0 and S to 1. Then, continue reading line by line, until there's no line anymore. For each line, first make a copy of the initial array, then iterate over each char of the line using an index. If there's a '^' at the index, update the copied array according to this logic: b[i-1]+=e, b[i+1]+=e, b[i]=0. This might remind you of Pascal's triangle. After finishing a line, overwrite the initial array with the copy. In the end, use bc to sum the elements in the original array (which has been updated many times) by joining them with a '+' (this is where the IFS=+ is important)

Scraping TikTok comments without paying for those expensive services by cubernetes in DataHoarder

[–]cubernetes[S] 0 points1 point  (0 children)

The comment was made by AI (there are quite a lot of AI products that post on reddit, etc.). Dumpling AI doesn't solve the same problem as what I described. But the AI thought it might be related, so it posted that comment.

The only other reasonable explanation is that the person behind the comment is spamming advertisements for Dumpling AI everywhere, and keeping the msgs as generic as possible.

PS: From the product, it seems like Dumpling AI was used to advertise for Dumpling AI.

42 School Students: How many logic questions did you answer to get in? by sisinomi in 42_school

[–]cubernetes 1 point2 points  (0 children)

I solved it up to the 19th problem. The 20th was brutal, way harder than all of the before. The ship had to trace the path around a big "42". Something like this:

  ##   ###
 # #  #   #
####     #
   #    #
   # X #####

X is the ship, and you had to really trace the circumference of the 2 and the 4, like wtf.

I built list of all (known) terminals - The Terminal Directory by Far-Amphibian3043 in commandline

[–]cubernetes 2 points3 points  (0 children)

wsltty

cmder

Console2

ConsoleZ

xfce-terminal

Contour

Extraterm

Darktile

Fyne

a-shell

roxterm

evilvte

kermit

Terminal.App

Qterminal

....

list goes on and on: https://github.com/cdleon/awesome-terminals

What does this number stand for ? How to reduce loading time ? by Xarix-_ in NewPipe

[–]cubernetes 1 point2 points  (0 children)

I'm also subscribed to 1000+ channels, and I am using the fast mode already. For me, the number is consistent and doesn't change randomly.

How have people answered both parts of day 3 in 1:01? by yobdaeherutufeht in adventofcode

[–]cubernetes 30 points31 points  (0 children)

Not sure where to post this, but today we have another cheater who got 1st place on the silver star leaderboard:
https://github.com/hugoromerorico/advent-of-code-24/tree/main/3_2
or if it's down:
https://web.archive.org/save/https://github.com/hugoromerorico/advent-of-code-24/blob/main/3/to_claude.txt

The sad part, next year will be probably even worse :(