r_bash – Telegram
🛠️ Bash Script: Recursively Convert FLAC to MP3, Organize by Metadata, and Auto-Install Dependencies

Hey all,

I made a simple but powerful Bash noscript to recursively convert `.flac` files into `.mp3`, auto-organize the output using embedded metadata, and optionally delete the original files or play a completion sound.

# 🔧 Features

* Converts `.flac` → `.mp3` using `ffmpeg`
* Extracts `ARTIST`, `ALBUM`, and `TITLE` from FLAC metadata
* Outputs files to: `./output/Artist/Album/track_noscript.mp3`
* Sanitizes filenames (no spaces or special chars)
* Optionally deletes original `.flac` files
* Optionally plays a completion `.mp3` via `mpg123`
* Auto-installs missing dependencies (where possible)

# 📦 Dependencies

Install manually, or let the noscript handle it:

bashCopyEdit# Debian / Ubuntu
sudo apt install -y ffmpeg flac mpg123

# Fedora
sudo dnf install -y ffmpeg flac mpg123

# Arch
sudo pacman -Sy --noconfirm ffmpeg flac mpg123

# macOS
brew install ffmpeg flac mpg123


# 📝 Example Usage

bashCopyEdit./flac_to_mp3.sh /path/to/flac --delete --play


# 📂 Output Structure

textCopyEdit./output/
└── Artist/
└── Album/
└── track_noscript.mp3


# 💾 Source + README

📁 [https://github.com/Blake-and-Watt/linux\_flac\_to\_mp3](https://github.com/Blake-and-Watt/linux_flac_to_mp3)
[https://ko-fi.com/makingagifree](https://ko-fi.com/makingagifree)

https://redd.it/1l1kzie
@r_bash
emoji picker noscript (macos)

Hi everyone, I made this noscript to work as an emoji picker. For some reason, the output is characters like this: üòÄ instead of the actual emoji. How can I fix this?

#!/usr/bin/env bash

selection=$(
# cut -d ';' -f1 "$HOME/.config/noscripts/stuff/emoji" | \
cat "$HOME/.config/noscripts/stuff/emoji" | \
choose -f "JetBrainsMono Nerd Font" -b "31748f" -c "eb6f92" | \
sed "s/ .//"
)

[[ -z "$selection" ]] && exit 1

printf "%s" "$selection" | pbcopy

osanoscript -e 'tell application "System Events" to keystroke "v" using {command down}'Hi everyone, I made this noscript to work as an emoji picker. For some reason, the output is characters like this: üòÄ instead of the actual emoji. How can I fix this? I will attach an image of the choose screen below.#!/usr/bin/env bash

selection=$(
# cut -d ';' -f1 "
$HOME/.config/noscripts/stuff/emoji" | \
cat "
$HOME/.config/noscripts/stuff/emoji" | \
choose -f "JetBrainsMono Nerd Font" -b "31748f" -c "eb6f92" | \
sed "s/ .
//"
)

[ -z "$selection" ] && exit 1

printf "%s" "$selection" | pbcopy

osanoscript -e 'tell application "System Events" to keystroke "v" using {command down}'

https://redd.it/1l2oxdm
@r_bash
What's your Bash noscript logging setup like?

Do you pipe everything to a file? Use tee? Write your own log function with timestamps?
Would love to see how others handle logging for noscripts that run in the background or via cron.

https://redd.it/1l38wbq
@r_bash
How to get an arbitrary integer to align with closest value in array

I have an array that looks like this array=(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100) and i want to calculate to which value from said array $1 will be closer to, so let's say $1 is 5, i want it to be perceived as 4, and if $1 is 87, i want it to be perceived as 88, and so on.
I tried doing it in awk and it worked, but i really want to get pure bash solution

https://redd.it/1l38vuw
@r_bash
How to delete multiple lines only AFTER a search pattern?

I have a file in the standard INI config file structure, so basically

; last modified 1 April 2001 by John Doe
owner
name = John Doe
organization = Acme Widgets Inc.

database
; use IP address in case network name resolution is not working
server = 192.0.2.62
port = 143
file = "payroll.dat"

I want to get rid of all key-value pairs in one specific block, but keep the section header. Number of key-value pairs may be variable, so a fixed line solution wouldn't suffice.

In the example above, the desired replace operation would result in

; last modified 1 April 2001 by John Doe
owner
name = John Doe
organization = Acme Widgets Inc.

database

Any idea how to accomplish this? I tried with sed, but I couldn't get it to work.

https://redd.it/1l3v0b7
@r_bash
BioBASH v0.3.12

https://preview.redd.it/vqfnz6mb955f1.png?width=1320&format=png&auto=webp&s=d4fa3b0e2260c507395add813ff53b70a45ed246

Hey guys this is a "side" project I started as part of my sabbatical leave. Basically is a Suite of tools for bioinformatics written in BASH.

https://github.com/ampinzonv/BB3/wiki

I am sure it has more bugs that i've been able to find, so this is the first time I publish any version, if you find it somehow interesting and are willing to contribute.

Best,

https://redd.it/1l45be3
@r_bash
How do I get a variable's value into a file in /sys/?

I want to create a noscript that will automate my battery charge threshold setup. What I used to use was:

sudo tee -a /sys/class/power_supply/BAT0/charge_stop_threshold > /dev/null << 'EOF'
70
EOF

I want to make it user-interactive, which I can do with read -p "enter a percentage: " number. So far I tried replacing 70 with $number and ${number}, which didn't work; $number and ${number} would appear in the file instead of the number I input in temrinal.

I tried replacing all three lines with sudo echo $number > /sys/class/power_supply/BAT0/charge_stop_threshold, but this results in a permission denied error.

How can I take user input and output it into /sys/class/power\_supply/BAT0/charge\_stop\_threshold?

https://redd.it/1l49hrh
@r_bash
How do I speed up this code editing the header information in a FASTA file?

This code is taking too long to run. I'm working with a FASTA file with many thousands of protein accessions ($blastout). I have a file with taxonomy information ("$dir_partial"/lineages.txt). The idea is to loop through all headers, get the accession number and species name in the header, find the corresponding taxonomy lineage in formation, and replace the header with taxonomy information with in-place sed substitution. But it's taking so long.

while read -r line
do
accession="$(echo "$line" | cut -f 1 -d " " | sed 's/>//')"
species="$(echo "$line" | cut -f 2 -d "" | sed 's///')"
taxonomy="$(grep "$species" "$dirpartial"/lineages.txt | head -n 1)"
kingdom="$(echo "$taxonomy" | cut -f 2)"
order="$(echo "$taxonomy" | cut -f 4)"
newname="$(echo "${kingdom}-${order}
${species}${accession}" | tr " " "-")"
sed -i "s/>$accession.*/>$newname/" "$dir
partial"/blast-results5000formatted.fasta
done < <(grep ">" "$blastout") # Search headers

Example of original FASTA header:

\>XP_055356955.1 uncharacterized protein LOC129602037 isoform X2 [Paramacrobiotus metropolitanus\]

Example of new FASTA header:

\>Metazoa-Eutardigrada_Paramacrobiotus-metropolitanus_XP_055356955.1

Thanks for your help!

https://redd.it/1l4d9th
@r_bash
How can I speed up this code?

This code is taking too long to run. I'm working with a FASTA file with many thousands of protein accessions ($blastout). I have a file with taxonomy information ("$dir_partial"/lineages.txt). The idea is to loop through all headers, get the accession number and species name in the header, find the corresponding taxonomy lineage in formation, and replace the header with taxonomy information with in-place sed substitution. But it's taking so long.

while read -r line
do
accession="$(echo "$line" | cut -f 1 -d " " | sed 's/>//')"
species="$(echo "$line" | cut -f 2 -d "" | sed 's///')"
taxonomy="$(grep "$species" "$dirpartial"/lineages.txt | head -n 1)"
kingdom="$(echo "$taxonomy" | cut -f 2)"
order="$(echo "$taxonomy" | cut -f 4)"
newname="$(echo "${kingdom}-${order}
${species}${accession}" | tr " " "-")"
sed -i "s/>$accession.*/>$newname/" "$dir
partial"/blast-results5000formatted.fasta
done < <(grep ">" "$blastout") # Search headers

Example of original FASTA header:

\>XP_055356955.1 uncharacterized protein LOC129602037 isoform X2 [Paramacrobiotus metropolitanus\]

Example of new FASTA header:

\>Metazoa-Eutardigrada_Paramacrobiotus-metropolitanus_XP_055356955.1

Thanks for your help!

https://redd.it/1l4d8d4
@r_bash
help with bash noscript

i have made my nvim configuration and i wanted to do a noscript for installing all the dependencies and things like that, but some of the packages (like lazygit) won't install, can you help me?

since the file is 1402 lines long i will put a link

https://redd.it/1l5xydx
@r_bash
Cybersecurity, AI and MacOS Learning plan - Thoughts?

Hey everyone! I’m on week 2 of a 12-week, plan of expanding my knowledge in Cybersecurity, AI, Bash and MacOS. **I’m looking for:**

* Suggestions on improving my shell noscripts or aliases
* Best practices for file permissions, Git workflows, and CI/CD in a security context
* Recommendations for next challenges (CTFs, labs, or open-source tools)

I am a beginner and **so far I learnt:**

* Basic Bash/Terminal/iTerm2 and Visual Studio - focused on getting very basics first
* Created a Repo to share all learnings and files
* Completed OverTheWire Bandit levels 0–6 - using it to reinforce point 1.
* Kept detailed notes and screenshots of my terminal work

**I’m looking for:**

* Suggestions on improving my shell noscripts or aliases
* Best practices for file permissions, Git workflows, and CI/CD in a security context
* Recommendations for next challenges (CTFs, labs, or open-source tools)
* Friendly feedback the plan and how my repo is looking :)

**Check out my repo & plan:**
[https://github.com/birdhale/secai-module1](https://github.com/birdhale/secai-module1)

Any insights, critiques, or pointers are welcomed!

https://redd.it/1l625np
@r_bash
CD shortcut

Is there a way i can put a cd command to go to the desktop in a shell noscript so i can do it without having to type "cd" capital "D", "esktop". Thanks

https://redd.it/1l69apz
@r_bash
Has anyone ever used /usr/bin/factor in a noscript?

Just discovered this command. Since it's part of coreutils I assume it has its uses. But has anyone ever used it in a noscript?

https://redd.it/1l6p0dp
@r_bash
sshm (SSHMenu) – Interactive, SSH Host Selector for Bash

Hey r/Bash! 👋

I’ve just published a tiny but mighty Bash noscript called **sshm.sh** that turns your ~/.ssh/config into an interactive SSH menu. If you regularly SSH into multiple hosts, this lets you pick your target by number instead of typing out long hostnames every time.

Out of all the noscripts I have written, this is the one I use the most. It is a single file that works on both macOS and Linux. It is a great way to quickly SSH into servers without having to remember their hostnames or IP addresses.

- Note: Windows support isn’t implemented yet, but it should be pretty flexible and easy to add. If anyone’s interested in contributing and helping out with that, I’d really appreciate it!



# 📂 Example ~/.ssh/config

textCopyEditHost production
HostName prod.example.com
User deploy
Port 22

Host staging
HostName stage.example.com
User deploy
Port 2222

Host myserver
HostName 192.168.1.42
User BASH
Port 1234



Running ./sshm.sh then shows:

Select a server to SSH into:
1) Root-Centos7-Linux 4) Root-MacbookPro 7) Kali-Linux
2) Root-Kali-Linux 5) Root-Rocky-Linux 8) MacbookPro-MeshNet
3) Rocky-Linux 6) MacbookPro 9) Centos7-Linux
Server #: <number>

https://redd.it/1l6vin0
@r_bash
Better ip --brief

https://preview.redd.it/ao1lfoqxmy5f1.png?width=894&format=png&auto=webp&s=de481dbb7b37e53ffe31faadec25586d792a3f32

alias obscureIPv6='sed -E "s|m[23][0-9a-f]{3}:[0-9a-f]{1,4}:([^/]*?)/|m3fff:abc:\1/|g"'
function tracepath {
/usr/sbin/tracepath $@ | obscureIPv6
}

function ip {
/usr/sbin/ip -h -s --color=always $@ | obscureIPv6
}

alias obscureIPv6='sed -E "s|m[23][0-9a-f]{3}:[0-9a-f]{1,4}:([^/]*?)/|m3fff:abc:\1/|g"'


function tracepath {
/usr/sbin/tracepath $@ | obscureIPv6
}

function ip {
/usr/sbin/ip -h -s --color=always $@ | obscureIPv6
}
┌ sebastian@suse:0 ~/.bashrc.d (master)
└ $ cat 99-ip
function ipbrief {
/usr/sbin/ip --brief -h -s "$@" | \
awk '
BEGIN {# Farbcodes
r = "\033[31m" # rot
g = "\033[32m" # grün
y = "\033[33m" # gelb
reset = "\033[0m"}

NF == 0 { next } # Skip empty lines

{
# Routing Table
if ($1 ~ /[.]/) { # IPv4
printf("%s%-30s%s", g, $1, reset)
} else if ($1 ~ /[:]/) { # IPv6
printf("%s%-30s%s", y, $1, reset)
} else if ($1 ~ /default/) { # default route
printf("%s%-30s%s", r, $1, reset)
} else if ($1 ~ /unreachable/ ) { # for now drop unreachable routes
next
}

if ($2 ~ /via/) {
if ($3 ~ /[.]/) { # IPv4
printf("→ %s%-30s%s | %-15s\n", g, $3, reset, $5)
} else if ($3 ~ /[:]/) { # IPv6
printf("→ %s%-30s%s | %-15s\n", y, $3, reset, $5)
} else {
printf("→ %-30s | %-15s\n", $3, $5)
}
next
} else if ($2 ~ /dev/) {
printf("→ %s%-30s%s | %-15s\n", r, $3, reset, $5)
next
}

# Interface name, state, first address
if ($2 ~ "UP") {
printf("%-20s %s%-9s%s", $1, g, $2, reset)
} else if ($2 ~ "DOWN") {
printf("%-20s %s%-9s%s", $1, r, $2, reset)
} else {
printf("%-20s %-9s", $1, $2, $3)
}
# addresses
for (i = 3; i <= NF; i++) {
# skip metrics
if ($i == "metric") {
i++;
continue
}

# indentation
if (i > 3) {printf("%30s", "")}

if ($i ~ /\./) { # IPv4
printf("%s%-20s%s\n", g, $i, reset)
} else if ($i ~ /:/) { # IPv6 | MAC
printf("%s%-20s%s\n", y, $i, reset)
} else if ($i ~ /<.*?>/) { # additional link information
printf("→ %-20s\n", $i)
} else {
printf("\n")
}
}
# if no address is configured print newline
if (NF < 3) {printf("\n")}
}' | obscureIPv6
}

https://redd.it/1l7fb0g
@r_bash
My Personal Bash Style Guide

Hey everyone, I wrote this \~10 years ago but i recently got around to making its own dedicated website for it. You can view it in your browser at style.ysap.sh or you can render it in your terminal with:

curl style.ysap.sh

It's definitely opionated and I don't expect everyone to agree on the aesthetics of it haha, but I think the bulk of it is good for avoiding pitfalls and some useful tricks when noscripting.

The source is hosted on GitHub and it's linked on the website - alternative versions are avaliable with:

curl style.ysap.sh/plain # no coloring
curl style.ysap.sh/md # raw markdown

so render it however you'd like.

For bonus points the whole website is rendered itself using bash. In the source cod you'll find noscripts to convert Markdown to ANSI and another to convert ANSI to HTML.

https://redd.it/1l7kr1r
@r_bash
Using command separators (&&, ||) and here documents

I was messing around with for too long and thought I'd share a couple of ways to make this work (without set -e).

# 1 ) Put the command separator (&&, ||, or ;) AFTER the DECLARATION of the here document delimiter

#!/bin/bash

true &&
true &&
cat > ./my-conf.yml <<-EOF && # <-- COMMAND SEPARATOR GOES HERE
host: myhost.example.com
... blah blah ...
EOF
true &&
true

# 2 ) Put the command with the here document into a "group" by itself

#!/bin/bash

set -e
set -x

true &&
true &&
{ cat > my-conf.yml <<-EOF # <--- N.B.: MUST PUT A SPACE AFTER THE CURLY BRACE
host: myhost.example.com
... blah blah ...
EOF
} && # <--- COMMAND SEPARATOR GOES HERE
true &&
true

I tested this with a lot of different combinations of "true" and "false" as the commands, &&, ||, and ; as separators, and crashing the cat command with a bad directory. They all seemed to continue or stop execution as expected.

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