r_bash – Telegram
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
Sleep behaviour in suspension

I can't find a clear answer for this anywhere so I will be asking it here.

I want to write a simple noscript that randomly rotates my wallpaper using waypaper every hour with a simple infinite loop, as follows:

while :
do
sleep 3600
waypaper --random
done

# not even sure if this is the cleanest way to do this, I'm a noob

I can't find a clear answer for suspension behavior, however.

My system suspends after 30 minutes. Say it suspended exactly 30 minutes after the sleep timer started. If my computer doesn't wake up for an hour after suspension (1 hour, 30 minutes after sleep started) and comes back, will the sleep command continue from 30 minutes (where it left off), or calculate the time after suspension begin, run waypaper --random, and skip another 30 minutes. Or would it just skip to 0, run the waypaper command, and restart the timer?

I know I could just test it out with echo commands but it's much easier to ask someone knowledgeable. Thanks!

https://redd.it/1l762qu
@r_bash
cat file | head fails, when using "strict mode"

I use "strict mode" since several weeks. Up to now this was a positive experience.

But I do not understand this. It fails if I use `cat`.

```
#!/bin/bash

trap 'echo "ERROR: A command has failed. Exiting the noscript. Line was ($0:$LINENO): $(sed -n "${LINENO}p" "$0")"; exit 3' ERR
set -Eeuo pipefail

set -x
du -a /etc >/tmp/etc-files 2>/dev/null || true

ls -lh /tmp/etc-files

# works (without cat)
head -n 10 >/tmp/disk-usage-top-10.txt </tmp/etc-files

# fails (with cat)
cat /tmp/etc-files | head -n 10 >/tmp/disk-usage-top-10.txt

echo "done"
```

Can someone explain that?

> GNU bash, Version 5.2.26(1)-release (x86_64-pc-linux-gnu)

https://redd.it/1l8tjbx
@r_bash
Need Help Finding a Specific Config File in Linux

How to Find a Config File Created After 2020-03-03 (Size Between 25k and 28k)

I'm trying to track down a configuration file that meets these criteria:

Created/modified after March 3, 2020
Between 25KB and 28KB in size
Likely has a .conf or .cfg extension

I tried this command:

find / -type f \\( -name "\
.conf" -o -name "*.cfg" \\) -size +25k -size -28k -newermt 2020-03-03 2>/dev/null

But I'm not sure if I'm missing anything. Some specific questions:

1. Are there other common locations besides /etc where configs might live?
2. Should I be using -cnewer instead of -newermt?
3. How would you modify this to also check file permissions?

https://redd.it/1l8zckm
@r_bash
Need Help: How to Check Services Listening on All Interfaces (IPv4 Only, Excluding Localhost)?

I’m auditing a system and need to find all services listening on all IPv4 interfaces (excluding localhost/127.0.0.1). Here’s what I’ve tried:



ss -tuln | grep -v "127.0.0.1" | awk '$5 !\~ /:::/ {print $5}' | cut -d: -f2 | sort -u



Questions:

1. Is this accurate?
2. Should I use netstat instead of ss for legacy systems?
3. How to also filter out IPv6 (:::) without complicating the command?

Context:

Target: Debian 12 server
Goal: Identify potentially exposed services (e.g., MySQL, Redis) bound to `0.0.0.0` or external IPs.

https://redd.it/1l92p9k
@r_bash
Bash noscript - How to check string length at specific loop iteration?

I'm working on a noscript that repeatedly base64 encodes a string, and I need to get the character count at a specific iteration. Here's what I have:

**#!/bin/bash**
**var="nef892na9s1p9asn2aJs71nIsm"**

**for counter in {1..40}**
**do**
**var=$(echo $var | base64)**
**# Need to check length when counter=35**
**done**

**What I need:**
When the loop hits iteration 35, I want to print ONLY the length of **$var** at that exact point.

**What I've tried:**

1. **${#var}** gives me length but I'm not sure where to put it
2. **wc -c** counts extra bytes I don't want
3. Adding **if \[ $counter -eq 35 \]; then echo ${#var}; fi**  but getting weird results

**Problem:**

* The length output disappears after more encodings
* Newlines might be affecting the count
* Need just the pure number as output

**Question:**
What's the cleanest way to:

1. Check when the loop is at its 35th pass
2. Get the exact character count of **$var** at that moment
3. Output just that number (no extra text or newlines)

https://redd.it/1latikt
@r_bash
Using cut to get versions

Suppose I have two different styles of version numbers:
- 3.5.2
- 2.45

What is the best way to use cut to support both of those. I'd like to pull these groups:

- 3
- 3.5

- 2
- 2.4

I saw that cut has a delemiter, but I don't see where it can be instructed to just ignore a character such as the period, and only count from the beginning, to however many characters back the two numbers are.

As I sit here messing with cut, I can get it to work for one style of version, but not the other.

https://redd.it/1lbtgyg
@r_bash
tzview - Display in local time lunchtime in other timezones.

I wrote a shell noscript that displays the current time in various
timezones. It is useful for organizing meetings with people in different
timezones, do not create a meeting at lunchtime to someone in Australia.

https://github.com/harkaitz/sh-tzview

https://redd.it/1ldj1fs
@r_bash
Rewriting a utility function noscripts library for Linux

I've made a simple utility functions noscripts librarytsilvs.bashlib for Bash.

Daily-driving Bazzite, I've designed it to simplify some interactions with Fedora Silverblue family of distros, especially rpm-ostree. But it might come in handy for active ADB and Git users too.

I'd like to reduce the amount of repetative code. If you have some time, review my code please. Re-implementation suggestions are welcome too.

tsilvs.bashlib: https://github.com/tsilvs/bashlib

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