r_bash – Telegram
Proper terminal settings

I am writing a terminal emulator in go, for some reason when pressing enter on a prompt with no command (just the $ sign) bash doesn't send a \\n... is it up to my terminal to manage that?
Edit: after some more testing:
dev@arch:~ ls<output of command>\n
dev@arch:~

even after typing a command, bash doesn't send a \\n
Edit 2: after even more testing, this happens on every value for $TERM except dumb. If $TERM=dumb bash sends \\n

https://redd.it/1hci742
@r_bash
Is this example valid?

I found an example in a Bash noscripting course teaching material:

#!/bin/bash

capslocker() {
local PHRASE="Goodbye!"
return ${PHRASE^^}
}

echo $(capslocker) # will result in “GOODBYE!”

As far as I know there is no way to return non-integer values from a function and return only sets $?. If I'm not mistaken, this code snippet doesn't make sense because in order to "return" a string, you need to use echo.

Am I right or am I wrong about something?

Source: https://imgur.com/AmNJeQ0 (sorry guys, I don't have direct link to the code snippets)

https://redd.it/1hc2j1h
@r_bash
Help with UserLAnd terminal? Don't mind the face lol
https://redd.it/1hcqpa5
@r_bash
bash profiler to measure cost of execuction of commands

I couldn't find or was not satisfied with existing tools for profiling the speed-ness of execution of Bash noscripts, so I decided to write my own. Welcome:

https://github.com/Kamilcuk/L\_bash\_profile

It is "good enough" for me, but could be improved by tracking PIDs of children correctly and with some more documentation and less confusing output. I decided to share it anyway. The profile subcommand generates profiling information by printing timestamped BASHCOMMAND using DEBUG trap or set -x. Then `analyze` subcommand can analyze the profiling data, subtracting the timestamps, print summary of the most expensive calls, generate a dot callgraph of functions or commands, or similar.

For example, is `sleep 0.1` faster than `sleep 0.2`? Let's make a contrived example.

$ L
bashprofile profile --before 'a() { sleep 0.1; }; b() { sleep 0.2; }' --repeat 10 -o profile.txt 'a;b'
PROFILING: 'a;b' to profile.txt
PROFING ENDED, output in profile.txt
$ L
bashprofile analyze profile.txt
Top 4 cummulatively longest commands:
percent spent
us cmd calls spentPerCall topCaller1 topCaller2 topCaller3 example
--------- ---------- --------- ------- -------------- ------------ ------------ ------------ -------------
66.3129 2019599 sleep 0.2 10 201960 b 10 environment:5
33.4767 1019553 sleep 0.1 10 101955 a 10 environment:5
....some more lines...

Well, sleep 0.2 tool 201960 microseconds per call and sleep 0.1 took 101955 microseconds per call, so very suprisingly sleep 0.1 is faster.

Maybe someone will profit from this tool and even motivate me to develop it some further, so I decided to share it. Have fun.

https://redd.it/1hdncbl
@r_bash
Inputing bash through a userLAnd terminal is going to make my head explode.
https://redd.it/1hdmspg
@r_bash
dLine: command-line productivity tool

If you hate multitasking while you're deep in your IDE, I feel you. I always wanted a calendar that lives right in my terminal - something that can keep track of notes, deadlines, meetings, and events, while also reminding me when something important comes up.

So, I built dLine! 🎉

dLine: command-line productivity tool

It’s a bash noscript that not only manages your schedule but also fetches public and school holidays (only EU countries are supported for now) and even syncs with your Google Calendar. Perfect for keeping your life in check without ever leaving your terminal (IDE).

Check it out and let me know what you think!

https://redd.it/1hdsuaa
@r_bash
made my first (actually) bash noscript for first time

I written little bash noscripts before, they we're either just things to start wm and unfinished personal projects that was only for me, so I think I can count that one project as my first actually project that subreddit looked like where I should share it so I'm posting it in here

timecomp.sh: small noscript compare two different command with time command, with nice UI

preview

please tell me if you find something missing in the noscript or if its bad and why. I share it for getting review from other people and improve

(sorry for my bad grammar I'm not good at english)

github repo:https://github.com/LeVeryEpicUsername/timecomp.sh/tree/main

https://redd.it/1herubj
@r_bash
Apash Library

Hello World,

I would like to share with you a library written in shell noscript (bash/zsh): Apash
Apash provides a readable interface for performing simple operations available in shell noscript like in the other languages.
It is inspired by the Apache commons libraries.

This work leads me to render the interface compatible between shells like bash and zsh (for the moment).
It's relatively easy to contribute with your own snippets.

You can fully install it by following the procedure or just run a container ready to use:
docker run --rm docker.io/hastec/apash:0.2.0-ready 'StringUtils.upperCase "Do or do not, there is no try."'


Alternatively, you can use a minified version (just source and forget):
# Download version for bash
curl "https://raw.githubusercontent.com/hastec-fr/apash/refs/tags/v0.2.0/bin/apash-bash-min.sh" -o apash-bash-min.sh

# Source
. ./apash-bash-min.sh

# Repeat the string
StringUtils.repeat 3 "Ho! "

# result: Ho! Ho! Ho!


Apash currently includes around 100 methods covering a range of common operations.
I wish that Apash could one day help at least another person around the world.
And if you like it, consider giving it a star, it could help me too.

Depending on your feedbacks, I will continue (or not) to render it compatible with ksh family.

Thank you for all the help you provide there and Happy end of the year !!

https://redd.it/1hffdy1
@r_bash
Your POV on my app.

Hi, I was wondering whether I should add GUI to my project here or not. It's an app I made which makes managing wine easier, from winehq repositories for enthusiasts like me to install the latest features.

Currently the 4.0 version is in development and adding more features to it.

What's your view on this? Should I do it in shell or Java?

https://redd.it/1hex5e9
@r_bash
Is there a way to delete all files and reset via Bash?

I have a VPS that I can access only via ssh, is there a way to factory reset purely via ssh/bash? Thanks in advance!

https://redd.it/1heider
@r_bash
Looking for examples of optimized bash environments for Ansible, Python, Bash development

I'm a fan of utilizing Cygwin for my development and like the feel of running in a CLI vs utilizing something like vscode. I'd like to optimize by bash environment with functions, aliases, etc. I'm looking for examples of useful bash functions or nice bashrc files to optimize development of Python, Ansible (YAML), Bash noscripts, etc.

https://redd.it/1hfwnux
@r_bash
Stackabrix, a simple terminal game
https://redd.it/1hg79en
@r_bash
Globbing expansion within variable

I notice this simple noscript behaves differently in bash and zsh

#! /bin/zsh
while read lin
do
echo DEBUG line $lin
done << EOJ
foo * bar
EOJ

In zsh I get the expected output `DEBUG line foo * bar`, but with bash the asterisk is expanded to a list of the files in the current directory. It happens with standard input as well as with HERE documents.

What bash setting could be causing this double evaluation/expansion after assignment, and how do I get similar behavoir to zsh? I do not have any glob or expansion parameter settings in my `.bashrc` so it seems to be a difference with the default bash settings in Ubuntu.

I do not want input text to be interpreted or expanded in any way unless I explicitly use `eval` or `$()`as this is a security risk.

https://redd.it/1hg8crb
@r_bash
Reflow-safe right-aligned text in terminal via bash?

For styling my PS1, I create a a separator line using ANSI escape codes to create a string of $COLUMNS spaces which is underlined in gray. A simplified form of this would be

PROMPT_COMMAND='PS1=$(printf "\[\033[4;37m%${COLUMNS}s\033[0m\]" " ")"\n\s-\v$ "'

https://preview.redd.it/gdv4df0m3d7e1.png?width=901&format=png&auto=webp&s=1a0d6b7860356d7b2b31dba3a384f3b15fc0c42d

However, this messes up the display when the screen contents get reflowed, e.g. switching from a maximized to a half-screen window. Then I get something awkward like this:

https://preview.redd.it/5dj8l8zh4d7e1.png?width=565&format=png&auto=webp&s=87b998dff60c1bb61c172d2884a3a54f577478b2

https://preview.redd.it/ev36rx2n4d7e1.png?width=901&format=png&auto=webp&s=715dac21d32ac06ef29c5fdd600dd46c09764712

Is it possible to instead genuinely *right-align* a text on the terminal, such that it remains at the right end even if *$COLUMNS* changes? Or, alternatively, is there a way to insert a horizontal line that self-resizes like *<hr>* in HTML?

https://redd.it/1hg5ouj
@r_bash
Matches - A CLI game I coded in Bash

It's based on a two player game that was played in the trenches of World War One.

I made the game as an exercise in learning three new skills with Bash.

YouTube video showing the game being played: https://www.youtube.com/watch?v=24Wrz82JowA

Git Repo to download the game: https://git.zaks.web.za/thisiszeev/matches

Download it, try it out, give me feedback, something something something, profit.

https://redd.it/1hgq6r3
@r_bash
Two different while loops

Is there a functional difference between these two while loops:

find /path/ -type f -name "file.pdf" | while read -r file; do
echo $file
done


while read -r file; do
echo $file
done < <(find /path/ -type f -name "file.pdf")

https://redd.it/1hh3kpt
@r_bash
simple bash noscript/syntax help?

Hi there -

I'm looking for help with a fairly simple bash noscript/syntax. (If this isn't the right place, let me know!)

I am trying to write a noscript that will be run frequently (maybe every 10 minutes) in a short mode, but will run a different way (long mode) every 24 hours. (I can create a specific lock file in place so that it will exit if already running).

My thinking is that I can just...

* check for a timestamp file
* If doesn't exist, run **echo $(date) > tmpfile** and run the long mode(assuming this format is adequate)
* if it exists, then pull the date from tmpfile into a variable and if it's < t hours in the past, then run the short mode, otherwise, run it the long mode (and re-seed the tmpfile).

Concept is straightforward, but I just don't know the bash syntax for pulling a date (string) from a file, and doing a datediff in seconds from now, and branching accordingly.

Does anyone have any similar code snippets that could help?

https://redd.it/1hh2wfx
@r_bash
any way I can improve this bash noscript that has double stow command?

stow doesn't delete. It can only throw error or use --adopt to overwrite MY REPO's files instead of overwriting computer files with dotfiles.
I know normal ln can overwrite destination files like this:
ln -sf ~/.dotfiles/alacritty ~/.config/alacritty


but I want to use stow. Current config works decently well but I was wondering if I can replace 2 stow lines with 1?

# this code clones repo, runs install noscript, cd's into that repo, uses stow to distribute files via stow.

# I need to repeat stow twice. First so that if files exist already, those files overwrite
# this git repo files, then I reset this repo and run stow again.
# all this because git stow can't overwrite files / directories if they are already present

git clone --recurse-submodules git@github.com:monoira/.dotfiles.git ~/.dotfiles &&
bash ~/.dotfiles/install_noscripts/_install.sh &&
cd ~/.dotfiles &&
stow -v --adopt alacritty cmus git nvim sqlfluff tmux zsh &&
git add . && git reset --hard &&
stow -v --adopt alacritty cmus git nvim sqlfluff tmux zsh


https://redd.it/1hh740o
@r_bash
Find files larger than X mb and promp to delete/skip each one found

Hi. I've asked Gemini, Copilot, Claude, etc. for a bash noscript to find files larger than X mb (this should be a parameter to the noscript) starting in the current path, recursively, and then read (prompt) a question to delete or skip each one found.

I've got this:

#!/bin/bash

if [ $# -ne 1 ]; then

echo "Usage: $0 <size_in_MB>"

exit 1

fi

size_in_mb=$1

find . -type f -size +"${size_in_mb}M" | while IFS= read -r file; do

# Get the file size

size=$(du -h "$file" | cut -f1)

echo "File: $file"

echo "Size: $size"

while true; do

read -p "Do you want to delete this file? (y/n): " choice

case "$choice" in

[Yy]* )

rm "$file"

echo "Deleted: $file"

break

;;

[Nn]* )

echo "Skipped: $file"

break

;;

* )

echo "Please answer y or n."

;;

esac

done

done

When executing "./findlargefiles.sh 50", I'm getting an infinite loop of
"Please answer y or n."

Any ideas? I'm trying it on an Ubuntu 22.04 server

Thanks

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