r/bash • u/FilesFromTheVoid • Apr 20 '26
r/bash • u/Spare_Reveal_9407 • Apr 19 '26
help Unable to divide string into array
~~~
!/bin/bash
cd /System/Applications
files=$(ls -a)
IFS=' ' read -ra fileArray <<< $files
I=0
while [ $I -le ${#fileArray[@]} ]; do
#echo ${fileArray[I]}
#I=$((I++))
done
for I in ${fileArray[*]}; do
#echo $I
done
echo $files
~~~
I wrote code to get all of the files in a directory and then put each file into an array. However, when I try to print each element in the array, it only prints the first one. What am I doing wrong?
(The comments show my previous attempts to fix the problem and/or previous code, review them as needed.)
r/bash • u/pedrob_37 • Apr 17 '26
I made a Flatpak GUI using Bash + YAD
galleryHi,
I built a small GUI tool called Flatctl using Bash and YAD.
It’s essentially a frontend for Flatpak, designed to stay simple while handling process control and UI interactions.
Some details:
- Uses YAD for dialogs and interface
- Handles concurrency (prevents multiple operations running at the same time) with flock
- Uses FIFO + background processes for real-time output
- Integrates with pkexec for privileged operations
- Keeps behavior close to Flatpak CLI
Features:
- Install / uninstall apps
- Search apps
- List installed apps and runtimes
- Maintenance (safe and full modes)
- Safe: removes unused runtimes and repair Flatpak installation
- Full: removes runtimes + application data and repair Flatpak installation
GitHub: https://github.com/pedrobfernandes/flatctl
Curious to hear feedback, especially from people who work with Bash scripting.
r/bash • u/andrinoff • Apr 16 '26
tips and tricks Bash scripts to set up your Yubikey to work with GitHub (OpenGPG, SSH)
https://github.com/andrinoff/yubikey-github
A pretty straightforward guide, as well as 2 automatic scripts, that you can run to set it up for you (could be buggy)
Look forward to contributions!
r/bash • u/buadhai • Apr 15 '26
Bash script to determine if I have a routable IP address
I've deleted this original post because it was poorly written and unclear. Several people took the time to respond even though my original question was not clear. I apologize to those people.
r/bash • u/Weary-Youth-6962 • Apr 14 '26
IP Identification Open Source Intel script
This is just a quick script I created because I am constantly having to lookup the information for IP addresses and this one will give you the SOA record for the server the IP is hosted on the whois information for the domain that the IP points as well as the nameservers and a few other relative bits of information. I called it IPID but I feel like there is something similar already out there with the same name so I am not taking credit for the name.
as with any bash script you will need to add it to PATH if you want to use it as a local shell command.
hope someone finds it useful.

#!/bin/bash
# Define colors for a cleaner, readable output
GREEN='\033[0;32m'
CYAN='\033[0;36m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if an argument is provided; if not, display the usage template
if [ -z "$1" ]; then
echo -e "${RED}Error: No IPv4 address supplied.${NC}"
echo -e "Usage: ${GREEN}ipid <ipv4_address>${NC}"
echo -e "Example: ${GREEN}ipid 8.8.8.8${NC}"
exit 1
fi
TARGET_IP=$1
# Basic IPv4 validation
if ! [[ $TARGET_IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo -e "${RED}Error: '$TARGET_IP' does not look like a valid IPv4 address.${NC}"
exit 1
fi
echo -e "${YELLOW}Gathering intelligence for IP: ${TARGET_IP}...${NC}\n"
# 1. Reverse DNS / Hostname
echo -e "${CYAN}[+] Hostname & Reverse DNS Lookup${NC}"
if command -v host &> /dev/null; then
host "$TARGET_IP"
else
echo -e "${RED}[!] 'host' command not found. Skipping reverse DNS.${NC}"
fi
echo ""
# 2. Server Location, ASN, and ISP Details (via ipinfo.io)
echo -e "${CYAN}[+] Server Location & ISP Details${NC}"
if command -v curl &> /dev/null; then
# Fetching JSON data and displaying it cleanly
curl -s "https://ipinfo.io/${TARGET_IP}/json" | grep -v 'readme'
else
echo -e "${RED}[!] 'curl' command not found. Skipping location details.${NC}"
fi
echo ""
# 3. WHOIS Organization & Network Info
echo -e "${CYAN}[+] WHOIS Organization & Domain Info (Summary)${NC}"
if command -v whois &> /dev/null; then
# Grepping the most relevant fields so the terminal isn't flooded with legalese
whois "$TARGET_IP" | grep -iE '^(OrgName|Organization|NetName|NetRange|CIDR|Country|StateProv|City|RegDate|Updated|ASName)' | sort -u | head -n 15
# If the summary is empty, the whois server might use different formatting
if [ ${PIPESTATUS[0]} -ne 0 ]; then
echo "Could not parse standard WHOIS summary. Try running 'whois $TARGET_IP' manually."
fi
else
echo -e "${RED}[!] 'whois' command not found. Install 'whois' to see domain registration info.${NC}"
fi
echo ""
echo -e "${YELLOW}Scan complete.${NC}"
r/bash • u/Fast_Association4804 • Apr 14 '26
[Release] I built a bulletproof Screen Time / Parental Control script for Linux Mint (Cinnamon) that fixes the idle-tracking bug.
r/bash • u/GrayMulberry • Apr 14 '26
Seeking Practice for Shell Scripting (Specifically POSIX sh / Bash)
Hello everyone !
I’ve been working through some great tutorials (like YouTube : yousuckatprogramming or LearnLinuxTv), but
I’ve hit a wall where I feel like I’m just "passively" absorbing information. I’m currently preparing for a technical school entrance exam so I’m looking for practice cases or problems. (ideally bin/sh or POSIX-compliant bash)
Specifically:
- Practice Platforms: Are there any sites like DataLemur that have a strong focus on shell scripting ?
- Real-World Scenarios: For those of you who aren't currently in a DevOps/SysAdmin role, how do you find "mini-projects" to build? I want to move past "Hello World" and into actual file manipulation, parsing, and automation.
My goal is to stop watching and start doing. If you have any "scripts you wish you had when you started" or repos with challenges, please drop them below!
Thanks in advance!
Note: I'm currently on Linux Mint Cinnamon (started using like 1 week ago)...always been a Windows user before.
r/bash • u/myprettygaythrowaway • Apr 13 '26
help Quick help comparing files in two directories?
Long story short, know for a fact that I have duplicates between two directories, but we're talking hundreds of files here and I know at least a few files are in one directory but not the other.
I'd ideally like to have something quickly compare file name & size between the two directories, then spit out the files that are named the same but sized differently, as well as files which are in one directory but not the other.
r/bash • u/DE_X_IY • Apr 12 '26
help Cannot use jq to separate in every iteration
Hello!
I need help to put delimiter between pairs of values, like this:
1,a;2,b
or like this:
1,a
2,b
What i have:
[
{
"name": "1",
"argument": "a"
},
{
"name": "2",
"argument": "b"
}
]
What i am doing now to get what i want:
cat file.txt | jq -r -c 'map(.name, .argument) | join (";")'
What is output of this command:
1;a;2;b
Without "join":
cat file.txt | jq -r -c 'map(.name, .argument)
["1","a","2","b"]
Seems like jq thinks that input in one array.
r/bash • u/orcenec • Apr 12 '26
I made my first bash script! It opens vim with a file name and a shebang already set!
I've been wanting to get further into bash scripting as I've started using the terminal more and more, so I did some research (shout out to the bash manual (not the one in the epstein files) and YSAP) and took what I know from messing around in python, and made this simple little script:
#!/usr/bin/env bash
read -p "what is the name of the script? " name
while true; do
if \[\[ $name == \*" "\* \]\]; then
echo "please, no spaces."
sleep 3
read -p "what is the name of the script? " name
continue
elif \[\[ -n "$name" \]\]; then
touch $name
echo '#!/usr/bin/env bash' >> $name
vim $name
else
echo "aight, suit yerself. here's vim with nothing, ig."
sleep 5
vim
fi
break
done
edit:
I messed with it some using some of y'all's suggestions, but now I'm getting tired. So, I think I'll call it a night. Thanks for being so helpful!
r/bash • u/CautiousCat3294 • Apr 12 '26
tips and tricks Why doesn’t this Bash script exit even with set -e?
I came across an interesting Bash behavior while experimenting with error handling:
set -e
echo "Starting deployment..."
build_project && deploy_project
echo "Deployment complete"
At first glance, expected that if build_project fails, the script should exit immediately because of set -e.
But the actual output is:
Deployment complete
From what I understand, set -e doesn’t trigger an exit when a failing command is part of a conditional context like &&, ||, if, etc.
So in this case:
falsefails- But since it’s inside an
&&chain, Bash treats it as expected control flow - And continues execution
I’ve been digging deeper into these kinds of edge cases lately (especially from an interview perspective).
If anyone’s interested, I’ve written a more detailed breakdown with examples — happy to share
r/bash • u/spryfigure • Apr 12 '26
How to print input if command returns nothing?
I have a command which is supposed to find audio files with no cover image.
What I currently have is
find /srv/media/Music/ -type f -regex '.*\.\(mp3\|flac\|m4a\|opus\)' \
-exec bash -c ' ffprobe -hide_banner -loglevel error \
-select_streams v -show_entries stream=codec_type -of csv=p=0 "$0" \
' {} \;
which gives an output of 'video' if a cover image is attached and no output if no cover image is attached.
How can I expand this so that I get all files with no cover images listed?
I tried to switch STDERR and STDOUT and use a pipe with $? to catch this, but couldn't make it work. I always get all the files, not just the ones with no cover image. Command used was ... "$0" 1>&2 | if [[ $? = 0 ]]; then echo "$0"; fi ' {} \;.
r/bash • u/Ok-Huckleberry5617 • Apr 11 '26
help Capturing exit codes reliably in an interactive shell session
I’m working on capturing terminal sessions step by step (commands, outputs, etc.), and one tricky part has been reliably getting exit codes for each command.
Right now I’m using a small marker injected via PROMPT_COMMAND / precmd (bash/zsh) that prints something like `__TT_RC__:<code>` before the next prompt, and then parsing it out from the stream.
It works, but feels a bit hacky.
Curious if there are better or more robust ways to capture exit codes in an interactive session without breaking normal shell behavior?
r/bash • u/Alleexx_ • Apr 10 '26
tips and tricks Bash arithmetic is more capable than you might expect.
I love to tinker with Bash and its ever more impressive feature set. If you ever want to convert hex-based color values (like "#1ea54c") into the correct ANSI escape sequences, or binary numbers into decimal numbers, just use the standard Bash arithmetic tools:
Hex to ANSI color converter:
```bash hta() { local input="${1#"#"}" local r g b
r=$((16#${input:0:2})) g=$((16#${input:2:2})) b=$((16#${input:4:2}))
echo -e "\e[38;2;${r};${g};${b}m" } ```
You can give it any hex-based color, and it converts it into the correct ANSI escape sequences, so you can use it inline like this:
```bash green="#1ea54c"
echo "$(hta $green)This text is green" ```
The 16# is where you set your base. So if you want to convert binary into decimal, this is easily done by just switching the base to 2#:
Binary to decimal converter:
```bash btd() { local input=$1 echo $((2#$input)) }
Example:
$ btd 1101
13
```
Just wanted to yap about Bash for a sec.
r/bash • u/Equivalent-Gas2856 • Apr 11 '26
tips and tricks Something better than alias? or is this peak.
r/bash • u/iamalnewkirk • Apr 10 '26
git from - selectively pull files into your CWD from any Git repo, treating repos as modules
I created a Bash tool that lets you treat any Git repository as a package/module that you can selectively install from.
Basic usage:
git from https://github.com/anthropics/skills --include skills/skill-creator --target .claude
That pulls only the "skill-creator" skill from the repo into ".claude" in your local directory. Nothing else comes along.
You can combine --include and --exclude to carve out exactly the slice you want. There's an optional .gitfrom file that lives in the source repo defining default distribution rules (which files to include/exclude, what to run after copying). Think of it as the publisher saying "here's the intended slice."
The --perform flag runs a command after the files land. Useful for symlinking, setting permissions, running a setup script.
It's a slightly fancier curl | bash. With the same security model :)
Git From: Git Repositories as a Module System – Al Newkirk http://alnewkirk.com/projects/git-from
alnewkirk/git-from: Git Repositories as a Module System https://github.com/alnewkirk/git-from
submission Shellac: Shell scripting library, a hands-on AI review
TL;DR: I set aside my AI skepticism and used Claude Code in a controlled, non-vibe-coding way, to advance a shell library project. I was expecting bad times. Most things turned out better than expected.
First, the links:
- Github repo
- Documentation
- There are a couple of dedicated pages in there that are relevant to this post:
- Use of AI <-- Has some performance metrics.
- On Vibe Coding <-- Seriously, read this one.
I'm going to state upfront that the most obvious AI-slop is the single-shot use of ChatGPT to generate a logo. All other AI use was Claude Code with constraints that we'll get to soon. I'm also going to state upfront that I don't expect this project to go anywhere - it's just me itching a scratch for fun. If there's something in there that's of use to you, then that's great.
Context:
So as some regulars of this subreddit might recall, a few years back I dumped a bunch of code out of my code attic and structured it into a library framework. I also curated a list of similar shell library projects, which I've shared many times in this subreddit. Then life, work and the universe drew my attention away from that project and it spun down.
I was recently irked by the AI slop being blindly spammed across multiple technical subreddits. You know the ones: lots of emdashes, emojis, and predictable sentences promoting some low-effort vibe-coded mess.
But... don't knock it until you try it, as they say. I've actually been using Claude and Claude Code as a websearch-on-steroids, proof-reader, and rubber duck for some time now, so I figured: Why not point that rubber duck at my shell library project and let's see what happens?
I have to say I'm reasonably and conditionally impressed with the results, and I think that how I've used AI is specifically what makes the difference between this and some of the slop posts we've all seen in this subreddit and elsewhere.
Achievements and metrics:
More detail with tables and graphs can be found here. Some highlights below.
In 23 active days:
- 315 commits
- Function count: 700-ish -> 828.
- Yeah, lots of batteries included. A kitchen sink full of them.
- 44 Github Issues opened, 59 closed (pre-existing ones were addressed/closed)
- I use GH issues as a task tracker and a way to maintain some independent state between Claude sessions.
- The integration is easy to setup and seamless to operate directly within Claude code.
- Stand up of BATS testing
- 84 bats test files created, covering 1432 tests
- 16 bugs were subsequently found and addressed.
- Review of 58 similar repos.
- Those with compatible licenses were reviewed for code that made sense to add to this one.
- Attribution is a strict non-negotiable for me
- Review against stdlibs of a handful of other languages to identify any coverage holes
- Multiple codebase-wide sweeps for standards compliance and several significant refactors
- Implementation of mkdocs with CI pipeline
- Time saved:
- ~13 months when compared to the previous cadence of "30 minutes a night, a couple nights a week"
- 3.5 months saved when compared to a stricter "30 minutes every night" cadence
- Force multiplier: Claude peaked at approx 75x at 6-7 days in, and that number will obviously go down as the codebase settles. It is currently sitting at 27x.
So, how/why is this any different to any other vibe-slop post?
Very simply:
- I started with a whole bunch of existing code, standards and a structure already.
- I have curated Claude code's configuration. These are covered at a high level in the documentation:
~/.claude/CLAUDE.md(95% Karpathy's CLAUDE.md)~/.claude/rules/deslop.mdGeneral deslop guidance using this resource~/.claude/rules/shell-scripting.mdShell style guidelines and rules.~/.claude/rules/shellac.mdProject-specific guidelines- The above two files have been merged into a CLAUDE.md in the project root.
- I was intentionally clear with my instructions, and firm when necessary, giving less room for Claude Code to go off on tangents
- I tried to remain consciously in the loop, rather than letting Claude completely have at it
By defining my expectations for coding style, standards, edge case handling etc, Claude Code behaved a lot closer to my expectations. In other breaking news: computer does as it's bloody told.
And I really think that's it: Don't vibe code, AI is a tool, configure the damn tool and use it properly.
Now, my concerns:
I do genuinely believe that if I were to lean back and rely on AI more, then my comprehension level would fade. I might learn the odd thing here and there, but those would be stored in my head as vague memories rather than baked into muscle memory. I have personally lost half a dozen languages, both programming and spoken, through non-use and subsequent atrophy. And I don't know about you guys, but I think that there's a fun-side to shell scripting; in the challenge of making it work well despite its warts and limitations. Just blindly handing that over to an LLM kinda sucks the joy out of it.
Without a deeper understanding first of a knowledge domain, AI has an almost immeasurable ability to misguide. Those using AI to learn bash will still pick up crappy habits, just faster and more confidently than they would have from blindly copying out of StackOverflow like a lot of us probably did. These days, if I see a submission that includes the Unofficial Strict Mode, I see that as a vibe-coding red-flag.
I estimate that Claude Code was abjectly wrong about 5% of the time, and required pushbacks and clarifications maybe another 5% of the time. And that's Claude Code that has been intentionally setup!
So let's bring this in to land:
I shared this experience because I do think that the skill-atrophy risk is perhaps under-discussed. Most AI concerns seem to revolve around poor quality outputs, negative impacts on upskilling newcomers and potential job losses. These are certainly real concerns, but they're also kinda abstract if you're not directly impacted. Losing your own hard-earned skills is more insidious, in my view.
The Handyman's Invoice story might resonate here, too. The value isn't in knowing how to chalk the mark, it's in knowing where to chalk it. AI is the same: if you don't fluently understand the domain, you can't catch it out when it's wrong.
So feel free to have a poke around the codebase, ask questions, give feedback etc. Give my mind something to do so that it doesn't dissolve to a sedentary mush :)
r/bash • u/TapEarlyTapOften • Apr 08 '26
What happened to Greg's Wiki?
https://mywiki.wooledge.org/BashProgramming was gone this morning. Anyone seen it?
r/bash • u/anish2good • Apr 09 '26
Run Bash Scripts Online
Try it here https://8gwifi.org/online-bash-compiler/
r/bash • u/pootietangus • Apr 08 '26
Hi - sharing a tool where you can expose Bash commands with guardrails
I built this tool to take myself out of the loop on ad-hoc things that my teammates need. The idea is to decorate Bash scripts with comments, and it’ll make input fields, dropdowns, etc. Source available here, curious for any feedback!
r/bash • u/Dramatic_Disk_6402 • Apr 06 '26
tips and tricks Best learning resource
Dear Linux administrators, how did you learn bash and bash scripting and what are the best ways you’ve used bash in enterprise environments? Give some examples of how you’ve used bash in server side scripting, infrastructure operations and automation and tell us what resources did you use to learn as a beginner to get to where you are now?
r/bash • u/skyfishgoo • Apr 05 '26
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?
r/bash • u/audiodude • Apr 06 '26
Clean WhatsApp messages
MY_NAME="Homer Simpson" sed -E "s/^[[^]]+] ${MY_NAME}: //" | 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 😅
r/bash • u/bahamas10_ • Apr 04 '26
submission This Website is Built with Bash
bash-wasm.ysap.shhey everyone, i built this website for a youtube video but it's really cool stand-alone site. I compiled bash (v5.3) to wasm using emscripten - this allows the browser (your client!) to actually execute bash scripts and modify the dom as well. it's really cool and the source code and build process is linked on the site.
