cURL file upload patterns - multipart, batch uploads, xargs, and piping from stdin
Kept re googling the same cURL commands for uploading files, so I put everything in one place.
Covers:
\- Basic upload with -F
\- Auth headers and API keys
\- Looping through a directory
\- Parallel uploads with xargs
\- Piping tar output directly into an upload endpoint
\- What -F, -H, -X, -o, and --max-time actually do
\- Common errors like 413, 401, and 400, plus how to fix them
https://filepost.dev/blog/how-to-upload-files-with-curl
Hopefully this saves someone else the same trial and error.
https://redd.it/1sdvw2w
@r_bash
Kept re googling the same cURL commands for uploading files, so I put everything in one place.
Covers:
\- Basic upload with -F
\- Auth headers and API keys
\- Looping through a directory
\- Parallel uploads with xargs
\- Piping tar output directly into an upload endpoint
\- What -F, -H, -X, -o, and --max-time actually do
\- Common errors like 413, 401, and 400, plus how to fix them
https://filepost.dev/blog/how-to-upload-files-with-curl
Hopefully this saves someone else the same trial and error.
https://redd.it/1sdvw2w
@r_bash
FilePost
Upload Files with cURL: API Examples & One-Liners
Upload files with cURL using one-liners you can copy-paste. Covers multipart uploads, API key auth, multiple files, piping, and common flags like -F and -H.
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?
https://redd.it/1sdz4k9
@r_bash
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?
https://redd.it/1sdz4k9
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Shell function for installing/removing packages using fzf!
A shell function for removing/installing packages from AUR, system repos and flatpak mainly only using
https://redd.it/1se2jym
@r_bash
A shell function for removing/installing packages from AUR, system repos and flatpak mainly only using
fzf as dependency. Should work with most Arch Linux based distros(I am on CachyOS and works perfectly) if you have fzf, yay installed and AUR enabled :)mngpkg() {
local selections=$( (
yay -Slq | awk '{print "[yay-ins] " $1}' &
flatpak remote-ls flathub --columns=application | awk '{print "[flt-ins] " $1}' &
pacman -Qq | awk '{print "[yay-rm] " $1}' &
flatpak list --app --columns=application | awk '{print "[flt-rm] " $1}' &
wait
) | fzf --multi --header 'Search All Repos & Installed Apps (Tab to select)' \
--preview '
tag=$(echo {} | awk "{print \$1}");
pkg=$(echo {} | awk "{print \$2}");
if [ "$tag" = "[yay-ins]" ]; then
yay -Si "$pkg"
elif [ "$tag" = "[yay-rm]" ]; then
pacman -Qi "$pkg"
elif [ "$tag" = "[flt-ins]" ]; then
flatpak remote-info flathub "$pkg"
elif [ "$tag" = "[flt-rm]" ]; then
flatpak info "$pkg"
fi
' )
[ -z "$selections" ] && return
local yay_in=$(echo "$selections" | grep '^\[yay-ins\]' | awk '{print $2}')
local flat_in=$(echo "$selections" | grep '^\[flt-ins\]' | awk '{print $2}')
local yay_rm=$(echo "$selections" | grep '^\[yay-rm\]' | awk '{print $2}')
local flat_rm=$(echo "$selections" | grep '^\[flt-rm\]' | awk '{print $2}')
if [ -n "$yay_rm" ] || [ -n "$flat_rm" ]; then
printf "Delete app data and configuration files for removed packages? (y/N): "
read -r delete_data
fi
if [ -n "$yay_rm" ]; then
if [[ "$delete_data" =~ ^[Yy]$ ]]; then
echo "$yay_rm" | xargs -ro sudo pacman -Rns
else
echo "$yay_rm" | xargs -ro sudo pacman -Rs
fi
fi
if [ -n "$flat_rm" ]; then
if [[ "$delete_data" =~ ^[Yy]$ ]]; then
echo "$flat_rm" | xargs -ro flatpak uninstall --delete-data
else
echo "$flat_rm" | xargs -ro flatpak uninstall
fi
fi
if [ -n "$yay_in" ]; then
echo "$yay_in" | xargs -ro yay -S
fi
if [ -n "$flat_in" ]; then
echo "$flat_in" | xargs -ro flatpak install flathub
fi
}
https://redd.it/1se2jym
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Chronically - Interactive system administration CLI
https://github.com/fieldghost/Chronically
https://redd.it/1se9py7
@r_bash
https://github.com/fieldghost/Chronically
https://redd.it/1se9py7
@r_bash
GitHub
GitHub - fieldghost/Chronically: Help scheduling crontab without having to remember that stupid crontab syntax
Help scheduling crontab without having to remember that stupid crontab syntax - fieldghost/Chronically
Hi - sharing a tool where you can expose Bash commands with guardrails
https://redd.it/1sfxbf9
@r_bash
https://redd.it/1sfxbf9
@r_bash
radiosh - A minimalist, lightning-fast terminal radio player written in pure Bash
https://redd.it/1sg3yu0
@r_bash
https://redd.it/1sg3yu0
@r_bash
What happened to Greg's Wiki?
https://mywiki.wooledge.org/BashProgramming was gone this morning. Anyone seen it?
https://redd.it/1sg43dq
@r_bash
https://mywiki.wooledge.org/BashProgramming was gone this morning. Anyone seen it?
https://redd.it/1sg43dq
@r_bash
Tetris in bash
I had no reason to do this other than learning, but I got Tetris running in bash. I severely underestimated how hard this was going to be. But it works surprisingly well.
Learned way too much about terminal control along the way. Feedback welcome :)
Repo:
https://github.com/benny-e/bash-tetris.git
https://redd.it/1sgunm7
@r_bash
I had no reason to do this other than learning, but I got Tetris running in bash. I severely underestimated how hard this was going to be. But it works surprisingly well.
Learned way too much about terminal control along the way. Feedback welcome :)
Repo:
https://github.com/benny-e/bash-tetris.git
https://redd.it/1sgunm7
@r_bash
GitHub
GitHub - benny-e/bash-tetris: Tetris in bash
Tetris in bash. Contribute to benny-e/bash-tetris development by creating an account on GitHub.
what's the proper way to set a script to run on startup?
i tried to set protonvpn to connect automatically when i log in, and when it couldn't connect for the first time, cachy fully stopped booting lmfao
had to TTY in and delete the script just so it wouldnt hang on a black screen
am i an idiot for putting it in /etc/profile.d/ ? what's the safe way to go about it?
also open to good resources about bash scripting just for users, im not really doing any enterprise level shit and a lot of it seems geared towards that. i just wanna be a power user like i was with windows, 20 years of using that shit and i feel like a baby on linux :(
https://redd.it/1sh40jq
@r_bash
i tried to set protonvpn to connect automatically when i log in, and when it couldn't connect for the first time, cachy fully stopped booting lmfao
had to TTY in and delete the script just so it wouldnt hang on a black screen
am i an idiot for putting it in /etc/profile.d/ ? what's the safe way to go about it?
also open to good resources about bash scripting just for users, im not really doing any enterprise level shit and a lot of it seems geared towards that. i just wanna be a power user like i was with windows, 20 years of using that shit and i feel like a baby on linux :(
https://redd.it/1sh40jq
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Shellac: Shell scripting library, a hands-on AI review
**TL;DR:** I used Claude Code for advancing a shell library project and was expecting bad times. Most things turned out better than expected.
---
**First, the links:**
* [Github repo](https://github.com/rawiriblundell/shellac)
* [Documentation](https://rawiriblundell.github.io/shellac/)
* There are a couple of dedicated pages in there that are relevant to this post:
* [Use of AI](https://rawiriblundell.github.io/shellac/docs/Use%20of%20AI/) <-- Has some performance metrics.
* [On Vibe Coding](https://rawiriblundell.github.io/shellac/docs/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](https://en.wikipedia.org/wiki/Rubber_duck_debugging) 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](https://rawiriblundell.github.io/shellac/docs/Use%20of%20AI/). 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](https://rawiriblundell.github.io/shellac/docs/Use%20of%20AI/#guiding-inputs):
* `~/.claude/CLAUDE.md` (95% [Karpathy's
**TL;DR:** I used Claude Code for advancing a shell library project and was expecting bad times. Most things turned out better than expected.
---
**First, the links:**
* [Github repo](https://github.com/rawiriblundell/shellac)
* [Documentation](https://rawiriblundell.github.io/shellac/)
* There are a couple of dedicated pages in there that are relevant to this post:
* [Use of AI](https://rawiriblundell.github.io/shellac/docs/Use%20of%20AI/) <-- Has some performance metrics.
* [On Vibe Coding](https://rawiriblundell.github.io/shellac/docs/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](https://en.wikipedia.org/wiki/Rubber_duck_debugging) 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](https://rawiriblundell.github.io/shellac/docs/Use%20of%20AI/). 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](https://rawiriblundell.github.io/shellac/docs/Use%20of%20AI/#guiding-inputs):
* `~/.claude/CLAUDE.md` (95% [Karpathy's
GitHub
GitHub - rawiriblundell/shellac: The missing library ecosystem for shell
The missing library ecosystem for shell. Contribute to rawiriblundell/shellac development by creating an account on GitHub.
CLAUDE.md](https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/refs/heads/main/CLAUDE.md))
* `~/.claude/rules/deslop.md` General deslop guidance using [this resource](https://www.mooch.agency/deslop-a60e4b10f9df43f3bf6ea366eed1b31f)
* `~/.claude/rules/shell-scripting.md` Shell style guidelines and rules.
* `~/.claude/rules/shellac.md` Project-specific guidelines
* The above two files have been merged into a [CLAUDE.md in the project root](https://github.com/rawiriblundell/shellac/blob/main/CLAUDE.md).
* 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](https://rawiriblundell.github.io/shellac/docs/on_vibe_coding/), 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](https://www.snopes.com/fact-check/know-where-man/) 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 :)
https://redd.it/1shex3u
@r_bash
* `~/.claude/rules/deslop.md` General deslop guidance using [this resource](https://www.mooch.agency/deslop-a60e4b10f9df43f3bf6ea366eed1b31f)
* `~/.claude/rules/shell-scripting.md` Shell style guidelines and rules.
* `~/.claude/rules/shellac.md` Project-specific guidelines
* The above two files have been merged into a [CLAUDE.md in the project root](https://github.com/rawiriblundell/shellac/blob/main/CLAUDE.md).
* 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](https://rawiriblundell.github.io/shellac/docs/on_vibe_coding/), 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](https://www.snopes.com/fact-check/know-where-man/) 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 :)
https://redd.it/1shex3u
@r_bash
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:
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:
The
Binary to decimal converter:
---
Just wanted to yap about Bash for a sec.
https://redd.it/1shkx8q
@r_bash
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:
hta() {
local input="${1#"#"}"
local r g b
r=$((16#${input:0:2}))
g=$((16#${input:2:2}))
b=$((16#${input:4:2}))
eval "echo $'\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:
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:
btd() {
local input=$1
echo $((2#$input))
}
# Example:
# $ btd 1101
# 13
---
Just wanted to yap about Bash for a sec.
https://redd.it/1shkx8q
@r_bash
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:
That pulls only the "skill-creator" skill from the repo into ".claude" in your local directory. Nothing else comes along.
You can combine
The
It's a slightly fancier
Git From: Git Repositories as a Module System – Al Newkirk
https://alnewkirk.com/projects/git-from
alnewkirk/git-from: Git Repositories as a Module System
https://github.com/alnewkirk/git-from
https://redd.it/1shm586
@r_bash
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
https://alnewkirk.com/projects/git-from
alnewkirk/git-from: Git Repositories as a Module System
https://github.com/alnewkirk/git-from
https://redd.it/1shm586
@r_bash
Alnewkirk
Git From: Git Repositories as a Module System – Al Newkirk
Every Git repository is already a package. The only thing missing is an installer that respects "I only want a slice of this."
Something better than alias? or is this peak.
These all all the alias i have so far...
I work most in backend and infra side, to make my life easier i decided to do this, is there something more better i can do here, so is this peak?
https://redd.it/1siekh2
@r_bash
These all all the alias i have so far...
I work most in backend and infra side, to make my life easier i decided to do this, is there something more better i can do here, so is this peak?
https://redd.it/1siekh2
@r_bash
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?
https://redd.it/1sikx3i
@r_bash
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?
https://redd.it/1sikx3i
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
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
https://redd.it/1sj4fcx
@r_bash
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
https://redd.it/1sj4fcx
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
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:
* `false` fails
* 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
https://redd.it/1sjdkv5
@r_bash
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:
* `false` fails
* 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
https://redd.it/1sjdkv5
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
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 ' {} \;`.
https://redd.it/1sjefve
@r_bash
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 ' {} \;`.
https://redd.it/1sjefve
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community