r_bash
43 subscribers
346 photos
16 videos
8.42K links
Download Telegram
Function on .bashrc

Hello! I trying to add this function on my bashrc, but because of the quotes and single quotes, it's returning this error:
\-bash: .bashrc: line 142: unexpected EOF while looking for matching `''

\-bash: .bashrc: line 145: syntax error: unexpected end of file


The function is this one:
140 dwdb() {

141 local query="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME;"

142 sqlcmd -S link -d table -U user -P 'password' -C -Q "$query"

143 }

https://redd.it/1s5emg1
@r_bash
Exact timing of $PS0 and $BASHCOMMAND

I've had this line at the bottom of my ~/.bashrc for a while:

trap 'test "$BASH
COMMAND" == "$PROMPTCOMMAND" && printf "\e]2;$PWD\a" || printf "\e]2;$BASHCOMMAND\a"' DEBUG ;;

It uses a DEBUG trap to print the running command ($BASHCOMMAND) to the terminal emulator's title bar or else print the working directory ($PWD) if nothing is executing. I know some terminal emulators do this for you, but my favorite (urxvt) does not.

This has worked very well for me, but I recently learned about the $PS0 prompt, which is also run before the command executes, like a DEBUG trap, and I thought it might be a better way to implement this same thing.

It doesn't seem to be working, though, and I think the issue is in the timing of when $PS0 is shown and when $BASH
COMMAND is updated. When I add:

PS0="[\e]2;$BASHCOMMAND\a\]"

in my ~/.bashrc, the string in the terminal's title bar does update, but it's always one command behind (and the first is an odd test command). Is there any solution to this, like a way to update the $BASH
COMMAND sooner or an alternative way to get the command (from readline maybe?).

Or is the way I've already been doing this with the DEBUG trap likely still the best? I've always wondered how inefficient that is. It's all builtins, so I would hope not very, but I'm not too sure.

https://redd.it/1s4cx2x
@r_bash
Functions from my bashrc

My list of functions has gotten pretty long, thought maybe I'd share, [as asked](https://www.reddit.com/r/bash/comments/1s3lo2t/comment/ocgkhi1/). Share some interesting functions of your own, or any feedback you think I could use.

\>> [bashrc excerpt gist](https://gist.github.com/ekipan/1c2e5a6164fbe7601b32e089d889994c), and [permalink at time of post](https://gist.github.com/ekipan/1c2e5a6164fbe7601b32e089d889994c/adac6cb830131238a3666390d7574ec8a95f15be)

# a few of them:
e() { echo >&2 "$@"; "$@"; } # echo and run
hl() { bat -Ppl "${1:-help}"; } # highlight eg: find --help | hl
iftty() { if [[ -t "$1" ]]; then "${@:2}"; else cat; fi; }
opts() { iftty 0 "$@" --help |& rg "^\s*-" | hl; } # eg: opts find
# see gist for the rest.

A few I use _constantly_: gits() h() opts(). A ps1() that puts a newline if the last command didn't, so my prompt is on the left margin while scrolling back. A bit of whimsy like q() that I [adapted from a reddit post](https://www.reddit.com/r/zsh/comments/1rs6gcn/). I like the interface I designed for the path() function but since I only used it exactly once in my bashrc I just took it back out.

My style is definitely a lot more dense and nongeneric than most people or LLMs would like, but I own these functions and dense, direct code is better IMO.

**Background:** After my old Windows Thinkpad started getting a bit sick, I switched to using my Steam Deck as my main PC, with a dock, TV, and bluetooth keyboard. It seems a pretty good Arch flavor, and I wasn't entirely new to Linux, but I've learned a lot. One pain point is lack of manpages, so one of the first things I put in my .bashrc was a bunch of aliases to open my browser or curl from <https://cheat.sh>.

I had a ten-year-old account ended up shadowbanned, presumably because I posted a bashrc excerpt with URLs in it, maybe also because I'd forgotten about the account for years, idk. Thus the pastebin: I'm wary of posting too much code directly.

https://redd.it/1s3u7f5
@r_bash
-x () { local -; set -x; "$@"; }

Exhibit A in the case for "some kludges are good kludges".

https://redd.it/1s3lo2t
@r_bash
Could someone please review my scripting and give me criticism?

I made a script to manage my dotfiles on linux (arch btw).
Link to repo
https://codeberg.org/Flan-Angel/Dawtfiles/src/branch/main

Link to script
https://codeberg.org/Flan-Angel/Dawtfiles/src/branch/main/PushToSYS.sh


Tysm if you do end up checking it out :)

https://redd.it/1s42scy
@r_bash
passgen — Bash password generator (DB-safe, TUI)
https://redd.it/1s6uxiv
@r_bash
Terminal Native API Testing Tool is LIVE!

https://preview.redd.it/gq2fehb401sg1.png?width=1233&format=png&auto=webp&s=84566c1673098db1088664090ad091e0c01a3a0d


Hey guys!

Rust based API Testing Tool is now live,

# Y'all can download it from here: Volt


This is a minimalistic API testing tool right in the terminal itself which has a blazingly fast response window. It scans source files and lists every route instantly — axum, express, fastapi, next.js, and more so that you do not need to write the Endpoints or Base URLs manually.

Do check it out and let me know your thoughts.

The Binaries are available for MacOS, Linux, and Windows on the website. Feel free to drop issues if you find any.

https://redd.it/1s72ksw
@r_bash
for loop not indexing stuff in the {}'s

i can make a for loop like this

for i in {1..13} ; do
echo $i
done


and get each value for the index printed on a separate line

but if i let len=13

and try a loop like this

for i in {1..$len} ; do

echo $i

done



i get this output

{1..13}

is there no way to use a shell variable within the {}'s of a for loop?


https://redd.it/1sdcz2j
@r_bash
This media is not supported in your browser
VIEW IN TELEGRAM
Free online editor where you can write Bash scripts, run them, take notes, and export to PDF
https://redd.it/1sd0v1g
@r_bash
Clean WhatsApp messages

MYNAME="Homer Simpson" sed -E "s/^[[^]]+] ${MYNAME}: //" | sed -E "s/^[^]+] ^:+: /> /"

# Before

17:09, 4/5/2026 Homer Simpson: Nuclear plant back online!
17:09, 4/5/2026 Mr. Burns: Thank you for this. Who are you again?
17:10, 4/5/2026 Homer Simpson: Homer Simpson, sir 😅

# After

Nuclear plant back online!
> Thank you for this. Who are you again?
Homer Simpson, sir 😅

https://redd.it/1sdjuja
@r_bash