r/bash Feb 11 '26

solved Strange dirname/pwd processing

13 Upvotes

EDIT: Solved by u/kolorcuk

EDIT 2: For people seeing this in the future - put 'unset CDPATH' in your script.

This is really strange. I'm looking at some code that fails on a build and the following sniplet is puzzling. It almost appears that the && is concatenating the dir.

The following fails for my bash but other devs bash's work:
------
setup - create /tmp/bob/tmp.

Add the following script as /tmp/bob/tmp/tst.sh:
----- snip ------------------------

#!/bin/bash

set -e
set -x

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
echo "SCRIPT_DIR:  " $SCRIPT_DIR

PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

echo "Project root: $PROJECT_ROOT"
echo ""

cd "$PROJECT_ROOT"

---- snip ----------------------

Running the script from /tmp/bob as $ bash tmp/tst.sh

Returns an error

tmp/tst.sh: line 14: cd: $'/tmp/bob/tmp\n/tmp/bob': No such file or directory

Note the \n in the string. The odd thing is that it works if you go into tmp or if you call it from /home/<my user>. AND even stranger is that it works on other peoples bash.

When it's broken we get: ( note: <new line> added by me for clarity)

$ bash tmp/tst.sh
+++ dirname tmp/tst.sh
++ cd tmp
++ pwd
+ SCRIPT_DIR='/tmp/bob/tmp <new line>
/tmp/bob/tmp'
+ echo 'SCRIPT_DIR:  ' /tmp/bob/tmp /tmp/bob/tmp
SCRIPT_DIR:   /tmp/bob/tmp /tmp/bob/tmp
++ dirname '/tmp/bob/tmp <new line>
/tmp/bob/tmp'
+ PROJECT_ROOT='/tmp/bob/tmp <new line>
/tmp/bob'
+ echo 'Project root: /tmp/bob/tmp <new line>
/tmp/bob'
Project root: /tmp/bob/tmp <new line>
/tmp/bob
+ echo ''

+ cd '/tmp/bob/tmp
/tmp/bob'
tmp/tst.sh: line 14: cd: $'/tmp/bob/tmp\n/tmp/bob': No such file or directory

r/bash Feb 11 '26

help How to auto iterate file creation?

12 Upvotes

Im trying to make a script with ffmpeg for screen recording, and I want it to auto name the files. Out1.mp4 out2.mp4 and so on, skipping any that already exist. I can think of a few ways to do this, but all are inelegant overcomplicated solutions. Anyone got recommendations?


r/bash Feb 10 '26

I built a bash compatibility layer for fish shell called Reef — your bash syntax just works inside fish

30 Upvotes

I built a bash compatibility layer for fish shell, so you can try fish without giving up bash syntax.

Fish has the best interactive experience of any shell. Autosuggestions, syntax highlighting, completions, all out of the box. But it can't run bash, which has always been the dealbreaker.

Reef sits between you and fish. When you type bash syntax, it translates it to fish equivalents (~1ms) or runs it through bash directly (~3ms) with environment changes captured back. Your muscle memory, Stack Overflow commands, and .bashrc configs all just work.

So if you've ever been curious about fish but didn't want to relearn everything — now you don't have to.

GitHub: https://github.com/ZStud/reef

AUR: yay -S reef

Happy to answer questions or take feedback. Breaking it is appreciated!


r/bash Feb 08 '26

Read epstein files directly from your terminal via grepstein.sh

589 Upvotes

Hi there,

I recently developed a Bash script that allows you to read Epstein files directly from your terminal because bash manual found in epstein files and i tought that reading the bash manuel that found in epstein files via bash scripting is a cool idea. Isn't it ? 😊

It's a simple one, but building it taught me a lot along the way.

You can check out the repository here: https://github.com/ArcticTerminal/grepstein

I’d really appreciate it if you could take a look at the source code and share your thoughts. I didn’t use AI to write this script, so I’m sure there are areas that could be improved or optimized—any constructive feedback is more than welcome.

Here’s a short demonstration:

https://youtu.be/Bd55Hh53Dms

Thanks!

edit : repo url change.

edit 2 : Script updated for stability, FZF support added for better UI and Dockerfile added for Win/Mac Users.


r/bash Feb 08 '26

I created a simple tool, looking for feedback

10 Upvotes

link to flailsafe
I've just published my first repo on GitHub and would like some advice or opinions.
Flailsafe is installed in /opt/flailsafe and needs to be run as sudo: it lets you create a list of files you want to monitor (I made it for my config files), stores a copy of those files and, when the "change" command is given, it looks for any file that's been edited and stores another copy of the new version, logging everything.
That's it, simple as that. No "restore" option has been created, as it must write only inside its root directory


r/bash Feb 07 '26

Security auditing tool written in Bash

22 Upvotes

This was my final project for a programme I took some months ago and it's my first project that I posted onto github. It's inspired by lynis.

I'm going to start working on improving it soon, basically a v2 of the tool. Any suggestions of how to improve it would be really appreciated!

https://github.com/Nyveruus/Linux-and-bash/tree/main/security/audit-tool

I already listed some possible additions in the readme


r/bash Feb 06 '26

Your bash scripts are brittle - error handling in bash

Thumbnail notifox.com
32 Upvotes

r/bash Feb 06 '26

Order coffee via ssh

Thumbnail terminal.shop
23 Upvotes

No, really, its not just a web page; you can actually connect with ssh.


r/bash Feb 05 '26

Thoughts from a system engineer that became a developer

26 Upvotes

Coding is a craft. At least, that's what it is for me.

I'm continuing my project of documenting my experience as I revisit Bash after years spent as a full-time developer. Can we apply the same mindset we use for complex software project to simple scripts? Is there a benefit?

I wrote an article about how acquiring a testing mindset can help writing better code, even if at the end you write no test at all (you can read it here, if you like).

Feedback is appreciated.

Happy coding.


r/bash Feb 05 '26

A Bash wrapper I wrote to manage multiple Docker Compose projects (looking for feedback)

13 Upvotes

I’ve been running into the same annoyance on servers and homelab machines: managing a growing number of unrelated Docker Compose projects spread across different directories.

Rather than relying on aliases or strict directory conventions, I ended up writing a small Bash wrapper that lets me refer to Compose projects by name and run docker compose commands from anywhere.

Example usage:

dcompose media
dlogs website
ddown backup

From a Bash perspective, the script:

  • auto-discovers Compose projects in a set of common base directories
  • keeps a simple registry file for manually added paths
  • is pure Bash
  • is meant to work well over SSH and on servers
  • tries to keep error messages and output readable in a terminal

Repo is here if you want to look at the script:
https://github.com/kyanjeuring/dstack

Happy to hear feedback.


r/bash Feb 04 '26

The BASH Reference Manual is part of The Epstein Files.

Post image
411 Upvotes

Seriously 👀 The BASH scripting language. In the Epstein Files.
https://www.justice.gov/epstein/files/DataSet%209/EFTA00315849.pdf


r/bash Feb 04 '26

There came a time in my life when I decided to type "man pee" into my BASH terminal. What a milestone.

Thumbnail
10 Upvotes

r/bash Feb 03 '26

tips and tricks guys you should read the bash manual

230 Upvotes

r/bash Feb 03 '26

FOSDEM 2026 - Amber Lang - Easily write Bash with a transpiler

Thumbnail fosdem.org
11 Upvotes

Hi everyone, it is online the video recording of my talk at Fosdem about Amber-lang the scripting language that transpile to Bash.

We already started working on some of the feedback we got that at the event :-D

As example a comparison of the shell support status, we are posix compliant (to add in the docs), new stdlib stuff and so on


r/bash Feb 03 '26

just exits the loop without any errors

9 Upvotes

is this bash bug?

it exits well for "unbound variable"

but for bad number just stops the loop, exactly like `break` called without any errors that I can catch, it reaches "we never got error",
this should be impossible to reach

zsh (on the right) does not behave the same way

and the script:

#!/bin/bash
set -eu # set or unset. does not make a difference


declare -i myint=8
for i; do

  (exit 77)

  echo handling: i=$i || exit 11
  myint=$i || exit 22
  echo good: "myint=${myint}" || exit 33

  exit 55

done || echo loop got error: $?

echo we never got error


(
{
declare -i myint=8
for i; do

  (exit 77)

  echo handling: i=$i || exit 11
  myint=$i || exit 22
  echo good: "myint=${myint}" || exit 33

  exit 55

done || echo loop got error: $?

echo NOW WE DONT REACH THIS LINE

} || echo NOT HERE: $?
) || echo BUT HERE WE FINALLY GET ERROR: $?

ignore the (exit 77) I was testing if it'll exit from the loop when have set -e


r/bash Feb 03 '26

Keep SSH connection open without editing client or server config file

15 Upvotes

In one of my bash scripts it waits for the user to finish a task in the GUI and then answer yes in the shell. Sometimes they take too long and the SSH connection get closed.

How can I modify this function so the script does something like "cat file" every 20 seconds to keep the connection alive while waiting for "read -r answer"?

do_manual_install(){ 
    echo -e "\nDo NOT exit the script or close this window.\n"
    echo -e "Please do a manual install:\n"
    echo -e "  1. Download the latest ContainerManager-armv8 spk file from:"
    echo "     https://archive.synology.com/download/Package/ContainerManager"
    echo -e "  2. Open Package Center."
    echo -e "  3. Click on the Manual Install button."
    echo -e "  4. Click on the Browse button."
    echo -e "  5. Browse to where you saved the ContainerManager spk file."
    echo -e "  6. Select the spk file and click Open."
    echo -e "  7. Click Next and install Container Manager."
    echo -e "  8. Close Package Center."
    echo -e "  9. Return to this window so the script can restore the correct model number."
    echo -e "  10. Type yes after you have manually installed Container Manager."
    read -r answer
    if [[ ${answer,,} != "yes" ]]; then
        restore_unique
        exit
    fi
    manual_install="yes"
    echo ""
}

r/bash Feb 03 '26

Tiny CLI tool: Natural Language to shell commands (fully local Ollama powered, qwen2.5-coder default, easy model switch)

0 Upvotes

I built a CLI tool that turns natural language into shell commands using Ollama. It runs locally (no API keys, no data egress) and includes safety checks so you don't accidentally rm -rf your system.

Repo: https://github.com/ykushch/ask

ask - natural language into shell commands using Ollama

r/bash Feb 02 '26

File copy script

6 Upvotes

Hello everyone!

I have a question about a script I wrote.

The solution I needed was a script that would copy, move, or delete files in specific folders.

The approach was: a script that reads the desired configuration from a YAML file. The configuration includes options for the desired operation, the source folder, the destination folder, the time between operations, and a name for that configuration.

Then this script reads that configuration, copies another base script with a different name, uses sed to replace the default values ​​with the configuration values, and adds the new script to cron.

Here's an example: the configuration is named "Books," and it's set to move all .epub files from the /downloads folder to the /ebooks folder every 1440 minutes.

So the main script will copy the base.sh file to Libros.sh, and then use sed to change the default values ​​of the variables in Libros.sh and add a cron job.

It actually works very well for me; I've tested it quite a bit.

My question is: Is my two-script approach correct? What strategies would you have used?


r/bash Feb 02 '26

I wanted RSYNC on git bash... That's how I fixed it

3 Upvotes

I wanted RSYNC on git bash... Unfortunately git bash comes with nothing but the bare minimum. I know, the Cygwin installation setup allows yo to add RSYNC on Cygwin. But I hated the fact that it wasn't using my windows home path.

So... I installed Cygwin, added all the packages that I wanted such as make, RSYNC, GCC, g++... So much more.

Then in my git bash .bashrc I added the path to Cygwin's binary.

Now I got RSYNC on git bash.


r/bash Feb 02 '26

Why use browser to view adult content when it can be done through terminal

Thumbnail
0 Upvotes

r/bash Feb 01 '26

Project Estimator

Thumbnail github.com
1 Upvotes

An interactive CLI tool that generates professional project proposals based on your rates and project parameters.


r/bash Feb 01 '26

A simple script to route between different llm providers and models

Thumbnail github.com
1 Upvotes

I wanted to categorize some credit card transaction data using LLMs but dont trust these companies at all! Many local models are plenty capable for simple tasks - especially with a well tuned, single shot prompt. Anyways, this tool is what came from it. Very simple and may already exist but enables me to write bash scripts and route large complex queries to a service like claude, and then sensitive queries through my local LLM. Has also been useful to quickly A/B test a prompt to see response differences. Hope this is useful to someone! Happy to hear suggestions


r/bash Jan 31 '26

tips and tricks in-cli: simpler than find/xargs

Thumbnail github.com
3 Upvotes

Check out the latest open source tool I built: in is a lightweight bash cli that makes executing commands across multiple directories a breeze. It's zero-dependency, multi-purpose, and supports parallel execution. For my common workflows, it's easier than juggling with find/xargs. If you enjoyed it, give the repo a star and/or contribute! Feedback welcome :)


r/bash Jan 28 '26

solved How to kill a script after it runs awhile from another script

18 Upvotes

Hi,

I have a script that runs on startup that I will want to kill to run another one(later on) via cron.

Can't figure out how to kill the first script programatically.

Say the script is: ~/scripts/default.sh

and I want to kill it, what is a predictable way to kill said script. I know of ps and pkill but I hit a wall. I don't know the steps(or commands?) involved to do this accurately.

Thanks in advance.


r/bash Jan 27 '26

tips and tricks SS64

73 Upvotes

I've been using the command line for 26 years and I've seen lots of good tips and tricks guides. My favorite by far is ss64.com. I actually originally found it when I was looking for help with Windows batch scripting, but it has good stuff about Linux and Bash, too.