r_bash | Unsorted

Telegram-канал r_bash - r_bash

46

Credits: @r_channels & @reddit2telegram

Subscribe to a channel

r_bash

What is the most complicated bash script you ever wrote?



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

Читать полностью…

r_bash

🚀 Instead of indexing repositories, I let AI acquire context incrementally.
/r/LLMDevs/comments/1tyvjbe/instead_of_indexing_repositories_i_let_ai_acquire/

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

Читать полностью…

r_bash

HEREDOC including delimiter with $(...) vs `...`

Dealing with a strange behavior (or maybe it's expected but I don't know) regarding using `cat` \+ `HEREDOC` to assign a multi line block of text to a variable.


**Script**

#! /bin/bash
SEP='----------------------------------'


MYDOC=$( cat <<LIST
Testing a multi line
input assignment using \$()
LIST )
echo "$MYDOC"
# includes the delimiter at the end
echo "$SEP"


MYDOC=`cat <<LIST
Testing a mult line
input assignment using backtick
LIST
`
echo "$MYDOC"
# works as expected
echo "$SEP"


cat <<LIST
Testing a multi line
output using cat
LIST
# doesn't include delimiter
echo "$SEP"


MYDOC="Testing a multi line
input directly"
echo "$MYDOC"
# just shows the multi line string as expected
echo "$SEP"


**Output**

% bash -x heredoc.sh
+ SEP=----------------------------------
++ cat
+ MYDOC='Testing a multi line
input assignment using $()
LIST '
+ echo 'Testing a multi line
input assignment using $()
LIST '
Testing a multi line
input assignment using $()
LIST
+ echo ----------------------------------
----------------------------------
++ cat
+ MYDOC='Testing a mult line
input assignment using backtick'
+ echo 'Testing a mult line
input assignment using backtick'
Testing a mult line
input assignment using backtick
+ echo ----------------------------------
----------------------------------
+ cat
Testing a multi line
output using cat
+ echo ----------------------------------
----------------------------------
+ MYDOC='Testing a multi line
input directly'
+ echo 'Testing a multi line
input directly'
Testing a multi line
input directly
+ echo ----------------------------------
----------------------------------


**Question**

I know I don't need to do it this way (`cat` \+ `HEREDOC`) since just directly including the new lines in the variable assignment works, but I'm wondering why using the `$(...)` syntax includes the delimiter in the read when backticks do not? A bug or something I don't understand about command substitution? Everywhere I look says to avoid backticks as they are old and depreciated.

\*Note: everything I do with shell scripts is just hacking things together, I don't do it enough to be really good at it and still get tripped up by goofy behaviors. I tried the `$(cat <<LIST...)` method first because that's what came up in SO when I googled "bash multi line variable"



**System Info**

~ % system_profiler SPSoftwareDataType | grep 'System Version'
      System Version: macOS 15.5 (24F74)

~ % bash -version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin24)
Copyright (C) 2007 Free Software Foundation, Inc.




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

Читать полностью…

r_bash

What’s a robust Bash pattern for running N concurrent jobs with proper cleanup and exit code aggregation?

I’m trying to build a Bash script that processes a list of tasks in parallel with a fixed concurrency limit (e.g., 4 jobs at a time), but I also want it to behave robustly in real-world conditions.

Specifically, I want to:

Limit the number of concurrent background jobs using pure Bash (no GNU parallel).

Correctly capture and aggregate exit codes from all jobs.

Handle SIGINT/SIGTERM so that if the script is interrupted, it cleanly terminates all running child processes.

Avoid leaving orphaned or zombie processes.

I’ve experimented with wait -n, job control, and traps, but I’m running into edge cases where some processes don’t terminate properly or exit codes get lost.

What’s a solid pattern or structure in Bash to implement this kind of controlled parallel execution with proper signal handling and cleanup?

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

Читать полностью…

r_bash

curl ano.chat
https://redd.it/1txiujh
@r_bash

Читать полностью…

r_bash

How can I write a multi-line variable declaration to a file and then load it from the file elsewhere?

I have a variable declared over multiple lines:

INFO=$(cat \<<EOF
[
{"title": "ProjectName:", "value": "My Project"},
{"title": "Description:", "value": "Example"}
]
EOF
)

I need to write the variable to a file like this so I can load it and use it later somewhere else:

echo INFO=$INFO >> $env_file

When I load that file though the variable is malformed because it's over multiple lines:

source $env_file
cat $env_file
INFO= [
{"title": "ProjectName:", "value": "My Project"},
{"title": "Description:", "value": "Example"}
]

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

Читать полностью…

r_bash

Why does printf behave differently in a subshell?

$ printf "%-9s:" "since"
since :

$ y=$(printf "%-9s:" "since")

$ echo $y
since :

Why is the format not working in the subshell? It's the same printf:

$ which printf
/usr/bin/printf

$ y=$(which printf)

$ echo $y
/usr/bin/printf

And it's the same shell:

$ echo $SHELL
/bin/bash

$ y=$(echo $SHELL)

$ echo $y
/bin/bash

$ /bin/bash --version
GNU bash, version 5.2.37(1)-release (aarch64-unknown-linux-gnu)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html&gt;

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

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

Читать полностью…

r_bash

Help getting buttons and actions working on a dunst notification
https://redd.it/1tvum2p
@r_bash

Читать полностью…

r_bash

Problem with for loop in subshell

I have a problem executing a for loop under sudo, but under a subshell the problem is the same.

Simplified:

for i in * ; do

echo $i

done

gives a list files in the current directory.. But

bash for i in * ; do echo $i ; done

gives the error "syntax error near unexpected token `do ". bash -c .... does the same.

I probably have to escape sortieing, but what? Could someone maybe explain?

Thanks/

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

Читать полностью…

r_bash

learning bash ?

i just realized that i can very easily loose data (just lost a self hosted server of mine) and i want to learn how to do scripts to backup my files maybe daily and rewrite what i had on there if it changed but also not copy what did not change, where could i start ?
i know rsync has nice things to copy, and i could do it watch -n$(time) but i also would love to learn more because i want to make scripts for my i3blocks, i don't really use it to it's full just display basic data atm, one i tried to make a little dd scripts but it was a disaster and i nearly distroyed my pc

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

Читать полностью…

r_bash

Workflow CLI ottimizzato per la gestione SSH: come ho ridotto il tempo di switch tra server

Ciao a tutti,

Gestire un parco macchine via SSH tramite `~/.ssh/config` standard stava diventando inefficiente per il mio workflow. Ho scritto un'utility Bash che trasforma l'accesso remoto in un processo basato su menu interattivi:

* **Esperienza utente**: Invece di ricordare alias o digitare IP, lo script presenta un menu pulito, permettendo la selezione istantanea dell'host target.
* **Efficienza**: Ho ridotto drasticamente il tempo di latenza tra la scelta del server e l'ottenimento del prompt remoto, ottimizzando la gestione dei socket.
* **Semplicità**: Il tool è un unico file Bash che non richiede dipendenze, rispettando la filosofia di leggerezza dei sistemi Linux che utilizzo.

Il progetto è open source e disponibile qui: [LINK GITHUB](https://github.com/linux07source/ssh-manager-pro).

Sarei curioso di sapere: in ambienti con molti server, preferite mantenere configurazioni locali o utilizzate strumenti di astrazione per la selezione degli host? Come gestite la complessità quando il numero di macchine cresce?"

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

Читать полностью…

r_bash

read -p in background script?

What happens if read -p "Press [Enter] key to continue..." is run in background script?

Does it hang? etc.?

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

Читать полностью…

r_bash

[VinMail] Bash-ing out emails: built a Bash-based terminal mail manager for multiple email accounts
https://redd.it/1tr5qf7
@r_bash

Читать полностью…

r_bash

bai | AI shell-command helper
https://trans.github.io/bai/

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

Читать полностью…

r_bash

[Project] Bashqueues: A shell-native, policy-driven IPC and job management system (Seeking technical feedback)
/r/linux/comments/1tpfynb/project_bashqueues_a_shellnative_policydriven_ipc/

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

Читать полностью…

r_bash

What is the point of Zsh when Bash can do the same?
/r/zsh/comments/1tz1ar4/what_is_the_point_of_zsh_when_bash_can_do_the_same/

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

Читать полностью…

r_bash

I built a strong One Time Pin generator/verifier for Bash

I made this Bash library because my wife has me building a Telegram bot for public use and she wants users to have an OTP emailed to them when they first register on the bot.

I am building the Bot using Bash as it's just easier for me, but I couldn't find a solution I liked for OTP. So I built one.

OTPs are generated using three hashes, one generated from a string created using the current time to the minute, one generated from a string that is unique to the project, and the last generate from a string that is unique to the user.

When you verify the OTP, you can define how many minutes the OTP must be valid for, from 1 minute to 120 minutes. OTPs can be 4 digits up to 16 digits.

There is support for several Hash Digests that exist in most Linux systems, including Blake2, SHA512 and a few more.

Everything you need to get started is documented along with Bash files of each example documented, as well as two demo scripts, one to generate a 6 digit OTP from the command line and the second to verify it. The OTP from the demo scripts will be valid for 10 minutes.

Download it, try it out, give me feedback. Feel free to use it in your own projects as it is released under GPL3.

I am planning to port it to Perl, PHP and Python, making sure that an OTP generated in one language can be verified in another.

https://git.3volve.net.za/thisiszeev/zotp-bash

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

Читать полностью…

r_bash

Your Ai coding agent lives in the terminal. A Free Book so you can read what its doing.
/r/grid_theory/comments/1txzgsm/your_ai_coding_agent_lives_in_the_terminal_a_free/

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

Читать полностью…

r_bash

A Command-Line Quiz: Which Output Never Appears?
/r/commandline/comments/1txq9ip/a_commandline_quiz_which_output_never_appears/

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

Читать полностью…

r_bash

Bash overengineering AI agent

So Ive created an few md files to m my local agent overengineer bash scripts

Turned out pretty great...

Here is a link to the gemini gem if you want to try it out

gem link

And here is a little post I wrote on how Ive done it

My Bash Overengineering Assistant: A Blueprint for Building Specialized AI Architects

Hope someone will find it interesting

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

Читать полностью…

r_bash

TIL that nmcli dev wifi can summarize connection rate, signal, bars, and security type by BSSID and SSID.

```bash

nmcli dev wifi

```

It has a man page, which I also appreciate.


I'm unsure it is what I would use for BASH scripting a data connection logger, but it is an easy command to get a peek at the available networks.

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

Читать полностью…

r_bash

A shell function for when you sort of know the command but not the exact flags

Honest use case: I can never remember tar/find/ffmpeg syntax. So I type something close to what I mean, let it fail, and run oops. It re-runs the command, captures stdout+stderr, sends the command + error to an LLM, and evals the corrected version if I confirm.

It works for plain typos too, but the part I actually use is "I know roughly what I want, fix my syntax."

https://github.com/TheSolyboy/oops

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

Читать полностью…

r_bash

How are you moving scripts and command output between devices?
/r/ssh/comments/1tupb4z/how_are_you_moving_scripts_and_command_output/

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

Читать полностью…

r_bash

I ran rm -rf / inside a safe VM to show how fast Linux collapses (cybersecurity awareness demo)

A lot of beginners still copy/paste commands from forums, Discord, or GitHub without checking what they do.

So I made a short, dramatic demo showing what happens when you run the infamous destructive command:

rm -rf /

Don’t worry — everything was done inside a throwaway VirtualBox VM with snapshots.The goal isn’t to “destroy Linux for fun,” but to show:

• Why this command is so dangerous

• How attackers hide it inside malicious scripts

• How to audit shell scripts safely

• Why you should always test in a VM first

If you’re learning Linux, cybersecurity, or building a homelab, this might save you from a very bad day.

Video link in the first comment to respect subreddit rules.

Guided Links:

Linux safety

VirtualBox labs

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

Читать полностью…

r_bash

Removed by Reddit

Removed by Reddit on account of violating the [content policy. ]

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

Читать полностью…

r_bash

Bash Script notify-send
/r/linuxquestions/comments/1tsfj3q/bash_script_notifysend/

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

Читать полностью…

r_bash

I built a website to create custom prompts for bash and zsh
https://redd.it/1trdd7i
@r_bash

Читать полностью…

r_bash

[VinMail] Bash-ing out emails: built a Bash-based terminal mail manager for multiple email accounts
https://redd.it/1tqwgve
@r_bash

Читать полностью…

r_bash

Seeking advice: focus on advanced bash, learn basic python or both?

Hello all,

I want some advice as to what will be best to focus my attention on based on my situation. I work as a sysadmin/linux engineer and naturally I do quite a lot of bash scripting on the server side for reporting, troubleshooting, scheduling/automating.

I have been learning basic python from the automate-the-boring-stuff book as I never actually got into programming and felt I need a more "serious" language in my resume.

However in this sub I see a lot of bash code which seems quite advanced and in all fairness I didn't even now you can do some of these things with bash.

I don't intend to transition to a developer role but I believe being able to write more complex automation from scratch will make me a better "product" on the job market.

Questions:

For server side - when to use bash and when to use python?
What can python do for a sysadmin / engineer that bash can't?
Would you say it's more valuable to know bash at an advanced level rather than knowing both bash and python at a basic-intermediate level for someone in my field?
What would you consider advanced level of knowlegde in bash?

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

Читать полностью…

r_bash

I hope you find this script useful

I'm a new blogger on medium. I'm trying my best to write efficiently. Here is my new post. Please give me your thoughts.

In this article, I’ll walk you through analyzing table space usage and row counts using SQL Server system views and DMVs which is useful for performance tuning and database growth monitoring.

joyshaw987/analyzing-table-space-and-row-counts-68a21a81013d" rel="nofollow">https://medium.com/@joyshaw987/analyzing-table-space-and-row-counts-68a21a81013d

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

Читать полностью…
Subscribe to a channel