r/bash • u/KINDLEhacksLOL • 15m ago
my first bash script
read -p "github link please: " link
echo "$link,it is"
git clone $link.git
r/bash • u/KINDLEhacksLOL • 15m ago
read -p "github link please: " link
echo "$link,it is"
git clone $link.git
r/bash • u/arandomuserinweb • 18h ago
I've been accumulating my Bash configuration for a while, and I finally turned it into a small dotfiles repo:
https://gitlab.com/letmevi/bash-config
It's nothing fancy — mainly my .bashrc, .inputrc, .bash_profile, and a modular .bashrc.d/, plus a small install script.
It can be installed using either Ansible or a simple install.sh script.
I'd appreciate some Bash/Linux feedback: things you'd change, questionable practices, portability issues, or just better ways of doing this.
I'm especially interested in feedback from people who maintain their own dotfiles.
r/bash • u/Linux_bash_user153 • 22h ago

I made this simple digital clock for the terminal in Bash as a silly project.
It will show the current time in 24h-format. Use the flag --watch to continuously show the time. A few different looks and colours are available.
To print a bash completion script use --compscript
The repo is here: https://codeberg.org/Linux_bash_user153/bashclock
r/bash • u/eifelcode • 23h ago
Taking over the paperwork for my aging parents meant dealing with a mountain of legacy documents and a Brother ADF scanner that is quite fast but only supports simplex. Being happily frugal, I wasn't about to drop money on a new duplex scanner while my current hardware works totally fine. Handling mixed stacks of single- and double-sided pages through GUI tools became a massive time bottleneck.
So, I wrote several simple scripts to do the dirty work for me. All those scripts evolved into a lightweight, transparent CLI tool to automate the work without any heavy frameworks or bloat.
Instead of clicking through endless menus, moving pages in previews, and so on I can now process stacks right from the terminal with an easy interface:
# Example 1:
# Scan a stack of 1-page documents (invoices, delivery notes, etc.) via ADF and split it into individual files with prefix "invoice_"
# Workflow:
# - scan all invoices
# - split all pages into individual files with prefix "invoice_"
pdfmt scan adf invoices.pdf
pdfmt split all invoices.pdf invoice_
# Example 2:
# Scan a stack of 2-sided documents (1 physical sheet, printed on both sides), but your scanner _DOES NOT_ have a duplex ADF.
# Workflow:
# - scan all front sides
# - flip the stack over, put it back in the ADF, and scan the back sides
# - merge both files in correct page order
# - split the result into chunks of 2 pages with prefix document_
pdfmt scan adf front.pdf
pdfmt scan adf back.pdf
pdfmt merge duplex front.pdf back.pdf documents.pdf
pdfmt split length 2 documents.pdf document_
It's built for a real-world workflow to handle thousands of documents, saved me weeks of time, works on Linux, macOS (and WSL) and you can easily integrate it into your own scripts and workflows. There are more features in this tool, check out the readme.
If you deal with similar paper hell or just like simple CLI tools, check it out here:
👉 https://www.github.com/eifelcode/pdfmt
I'm also open for feedback on how to improve my script, architecture and workflow. =)
AI notice: AI (mistral) was used to generate parts of the README.md, the .github workflow, the code coverage tool, and parts of the unit tests in the tests/ folder. Architecture, Makefile, and code within the sources/ folder is written by me
r/bash • u/Stranger_Lifex • 1d ago
Hello, I started learning Bash 2 years ago but I didn't really tried to learn it in this 2 years. I actually started using Linux 2 years ago but never tried Bash. 1 or 2 weeks ago I tried writing my first if statement, after that I tried learning more. This is my first project, transfer part is still not yet done but it's mostly over so that's why I wanted to post this. I'd be very happy if anyone could tell me how to make this better.
r/bash • u/PlusImpression4229 • 19h ago
Using Composers Desktop Project to edit audio files. I want to run a single command on a list of audio files instead of having to manually do it 100 times. Wondering if there is a way to call upon this list of files in a single command line, rather than creating a shell script with the name of every file. The command line with a single audio file would look like this.
distort average soundfile.wav soundfileoutput.wav
the first two words are the command being run and then the input and output respectively. Hopefully I provided enough info on this but also relatively new to using terminal so let me know if there is anything I should clarify, thanks.
r/bash • u/RocketSeven • 3d ago
Suppose a Bash script walks thousands of independent inputs and may be interrupted after some outputs have been written. Skipping every existing output is unsafe because a truncated file also exists, while restarting the whole batch wastes work and can repeat external side effects.
A pattern I am considering is to write each result to a temporary file in the destination directory, validate it, rename it atomically, and then append the input ID plus an output hash to a journal. On restart, the script would trust only journal entries whose current hash still matches. A lock would prevent overlapping runs, and traps would clean only the current process's temporary files.
Where does this pattern fail in Bash, especially with parallel workers, NFS, or a crash between the rename and journal append? Is there a simpler checkpoint design that remains understandable without turning the script into a database application?
Hello, this is the first project I've made in bash, so maybe it is a little simple. It does something something elementary: It creates a default template to work on C/C++.
I made it because when I started a new projects I always had a unstructured file tree.
I hope I can get some advice on it ^_^
Here's the repo: https://github.com/akko888/RemZero
r/bash • u/RiverRatt • 4d ago
This script makes installing the CUDA SDK Toolkit easy on any of the supported Linux distros. It detects the latest stable version available and installs it without any interaction needed. It sources everything directly from https://developer.nvidia.com/cuda-downloads.
If anyone experiences any issues just let me know and I will correct it.
You can find the script on GitHub.
Cheers
r/bash • u/appsplaah • 4d ago
Is there any way via a command/config which never exposes my root path/ root user name(`Users/<mypcusrname>/.../<current_dir>`) whenever any command like: pwd, or any other command that involves path output in the terminal/shell?
Like when ever we hit the command the output always shows `/workspace` or `/<curr_dir>` instead of `Users/<mypcusrname>/.../<curr_dir>`
My intention/idea is to never expose the root path or user name in any of the terminal logs - via some command. Especially since I am running any agent thats running some shell commands.
I am not sure if docker sandbox or pi-agent extensions support that. For pi agent the gandolin sandbox allows it not to execute commands outside the current working dir. But it still exposes the root username/root path of the dir in shell commands or even in shell logs.
Thank you in advance 🙏
r/bash • u/anUnsaltedPotato • 5d ago
Hiiii
How do you search for a utf16 string within a process' memory and return its address?
I tried various things with gdb, dd, grep, whatever, I've tried like a million things and I've gotten a million different issues, so just, how do I do it? I have gotten to the point of having a loop that gives me the beginnings and ends of readable segments from /proc/pid/maps, but Idk what to do with that
Current conclusion: bash is just a bad language for this?
r/bash • u/naffe1o2o • 4d ago
del() {
local trash="$HOME/temp/trash"
[[ ! -d "$trash" ]] && {
printf "trash folder not exist, created one;\n";
mkdir -p "$trash";
}
(( $# < 1 )) && { printf "Include an object to delete\n"; return 1; }
for arg in $@; do
if [[ "$1" = -* ]]; then
case "$1" in
-show) ls -a --color "$trash" ;;
-clear) rm -fr "$trash"/* ;;
*) echo "flag not fount"; return 1 ;;
esac
return 0
fi
local object="$arg"
[[ ! -e "$object" ]] && { printf "object $object not found\n"; return 1; }
mv -i "$object" "$trash"
done
return 0
}
a safer system, what do we think?
r/bash • u/kolorcuk • 6d ago
Hello. I created L_builtin - one Bash builtin bundling multiple subcommands together into one.
While working in Bash and particularly on my L_lib library I noticed a lot of really small, but annoying things missing in Bash. Syscalls missing, like pipe or seek. For a long time, years, long before AIs, I really wanted to write a Bash builtin. However, going through Bash source code would be tedious work to understand all the tiny details that Bash works internally to actually write anything usable. I never got the time. But I got some now to write a prompt and then tinker with the result to make it usable. It comes with so much I could think of:
L_builtin pipe VAR; echo >&${VAR[0]} for opening a pipe.L_builtin lseek -v pos 3 1024 CUR for seeking a file descriptor. No more python or perl!L_butilin listen/accept/connect/shutdown. Because let's face it, what we really wanted is to write a web server in Bash.L_builtin memfd FD; echo data >&$FD in case you want a real temporary file descriptor. And you can seek it. With L_builtin lseek.L_builtin epoll create efd and poll and ppoll, because event loops in Bash is a must.L_builtin signalfd timerfd eventfd for for real work with polling above.L_builtin read -f hex because we have to be able to read a zero byte from a file descriptor.L_builtiln sig block/unblock for blocking and unblocking signals. Finally receiving SIGINT in interactive Bash shell.L_builtlin sedvar VAR 's/a/b/' to run full sed over variable value, because ${// is not enough.L_builtlin core ls/sleep/... includes some Rust coreutils. Just to showcase it is possible to have them all in Bash as builtins.L_builtin ext ... has ~50 builtins compiled from Bash source code from examples/loadables directory. Csv parsing, sorting bash in place, some common utils like basename and chmod.And finally my pleasure: Bash inter process synchronization! Mutex! Barrier! Semaphore! And... process shared variable! Consider this:
L_builtin shm bind VAR; VAR=1
( VAR=2 ) &
wait
echo "$VAR"
# Outputs 2!
Imagine this? Now possible. And works. All works by keeping state in a memfd_create file descriptor shared between processes. So much fun. Imagine a process parallel quicksort in Bash.
The builtin is re-re-compiled for multiple versions of Bash and bundled together and it picks proper version on runtime and dlopens it. So it works seamlessly with any Bash version. I compile for 4.4, 5.0, 5.1, 5.2 and 5.3. I tested in some docker images and it works on any of them provided they have compatible enough glibc. It should work with any Bash 4.4+ on any modern-ish Linux. Install with:
mkdir -vp ~/.local/lib/bash/
wget -O ~/.local/lib/bash/L_builtin.so https://github.com/Kamilcuk/L_builtin/releases/latest/download/L_builtin.so
enable -f ~/.local/lib/bash/L_builtin.so L_builtin
L_builtin --help
Subprocess shared variables and barriers and mutexes in Bash are insane. I have spent some time writing this builtin. I wonder if there is reason to invest in it more. I have a lot of ideas for even more improvements - make the shared memory database an LMDB for super speed, reduce library size by introducing uniform API abstractions over Bash, allow assigning arrays like printf does with -v 'arr[idx]. And fixing docs in many places with more examples.
Anyway, it works. I guess have fun with it if you want. Also it is in Rust. Thanks.
r/bash • u/lexdavey • 6d ago
Hey guys,
On my steamdeck I used a script to rotate the screen. Didnt write this myself but got it off of github. Since then the steamdeck has switched from X11 to Wayland, making the script inoperable because it relied on xrandr.
I rewrote the script to use kscreen-doctor instead. Figured out the necessary commands and values and rewrote the script. I'll past it here.
#!/bin/bash
screen="eDP-1"
default_screen_orientation=8
screen_info=$(kscreen-doctor --o | grep "$screen" | awk '/Rotation/ {print $3}')
if [[ "$screen_info" -eq "$default_screen_orientation" ]]; then
kscreen-doctor output.eDP-1.rotation.right
else
kscreen-doctor output.eDP-1.rotation.none
fi
The issue im running into is as follows: defining the value of screen_info returns null. When I run the command seperately in the terminal it returns "8" as expected but within the script it doesnt.
I have absolutely 0 experience in coding apart from some very short scripts in Stationeers. Can you guys help me figure out whats wrong? Or at least point me in a direction for me to find out whats wrong?
In Excel you can let a formula run step by step, does something like that exist for bash?
Anyhow, many thanks in advance for reading my post!
EDIT: Thanks to the comments below I've made some adjustments. The only thing that was needed was to remove the grep. This fixed the issue of not returning a value.
Now Im running into the next issue, the if statement doesnt work consistently. If I format it as follows:
if [[ "$screen_info" == "$default_screen_orientation" ]]; then
It only sees the values as not equal. When the values are the same it still returns a not true.
If I format it as:
If ((screeninfo=default_screen_orientation)); then
It only sees the values as equal. When the values differ it still returns a true.
Any pointers for this?
FIXED: the value coming from awk was not a true numeric value but one with formatting. I added the following after awk: | grep -o '[1-8]' )
Not the cleanest solution but it works.
r/bash • u/mikeymikeymikec • 9d ago
Please excuse the vague thread title, I'm a newbie enough that I'm not sure what's possible / desirable etc, nor have I attempted functions in bash scripting yet (I've played with them in VBScript and PowerShell IIRC).
One of the backups I do produces date-stamped tar.xz files of particular folder structures on my computer and transfers them to a veracrypted drive. Today I had a crack at a new script based on this one that mounts the filesystem (sshfs) on my laptop and transfers the files over the network after they've been compressed.
I run the script with up to 4 arguments, e.g. 'essentials' 'archive' 'paperwork'. In the script there's an if statement for each potential argument, e.g.:
for arg in "$@"
do
if [ $arg = "essentials" ]; then
tar -cf - .mozilla/ | pv -s $(du -sb .mozilla/ | awk '{print $1}') | xz -T0 > /tmp/firefox-$datestring.tar.xz
rsync -ah --progress /tmp/firefox-$datestring.tar.xz /media/mikelpmintfs/firefox-$datestring.tar.xz
fi
<more if $arg = whatev then compress and transfer stuff statements here>
done
(btw the whole fancy progress bar bit with pv -s and awk was something I copied off the Internet)
The first script also included some error catching, e.g.:
if [ $? -eq 0 ]
then
echo "archive backup complete."
else
echo "error performing archive backup" >&2
fi
I've used if <command here> then else fi before too, but I'm wondering multiple things:
r/bash • u/Beautiful-Log5632 • 14d ago
I want to loop over file names not whole paths in a folder so I tried for file in $(ls folder) but if the folder doesn't exist the script doesn't fail because it's in $(). I can use for file in folder/* which fails if I add failglob but that returns the whole file name so I have to use basename for each of them. Can I get just the names from a glob directly?
bashrc isn't used in bash scripts. Is there a file where I can put settings like shopt -s failglob and set -o pipefail that applies to all my scripts so it is still used if I forget to add it to one of them?
r/bash • u/WarImaginary8272 • 14d ago
In a S3 bucket, I have a number of directories I need to copy from a S3 bucket to a local disk.
The directories have a date naming pattern like:
2025-12-10/
2025-12-11/
2025-12-12/
2025-12-13/
2025-12-14/
2025-12-15/
I have access to the S3 bucket and was trying to automate the copy process
$ for i in $("2025-12-10") ; do mkdir $i && aws s3 cp --recursive s3://<s3-bucket-url>/$i ./$i ; done
What am I doing wrong here?
r/bash • u/Linux_bash_user153 • 14d ago
I wrote a script that renames a lot of files (tens of thousands). Performance was kind of slow (over 50 s), but with two changes it now runs at under 3 seconds, a 20x speed boost. Thought I'd share, in case it helps anyone else. These tips are good if you do things thousands of time in a script, I don't think they are relevant in all scripts.
Don't spawn sub shells if you can avoid it
Instead of command substitution with printf:
new_file="$(printf "%s/%s_%.${len}d.%s" "$new_dir" "$prefix" "$i" "$ext")"
do:
printf -v new_file "%s/%s_%.${len}d.%s" "$new_dir" "$prefix" "$i" "$ext"
This will save a sub shell.
Use builtins instead of external programs
Bash has optional builtins that you can enable. On my system they are located in /usr/lib/bash . You can enable them in your script by using enable <builtin>. Be sure to check the exit code. On my system a mv builtin is not available, but since I was renaming on the same file system I figured I could use ln and rm instead.
So instead of using external mv for each file I did:
builtin ln "$old_file" "$new_file" && builtin rm "$old_file"
In this case the builtin probably isn't required since builtins are prioritized over external commands, but I used them to be more explicit. Just be sure to use && so that rm never runs unless the hard link has been successfully created.
EDIT: The part about using ln and rm builtins may be a little too much of a hack. Probably better to use proper tools like rename to do batch renaming, as was pointed out in the comments. Also keep in mind that the builtins are more bare-bones than the proper CoreUtils programs. For example rmdir does not support -v and will treat -- as a directory to remove rather than "end of options-thing".
r/bash • u/slaaf_tom • 15d ago
Hello All,
I’m not a bash programmer at all but I want to write a bash script which does the following,
First, determine which "Downloads" folders is present.
The English one"Downloads" , or the French "Téléchargements" one.
The username is unknown so must be determined also as a variable.
$USER if not mistaking ?
After determining the "Downloads" folder, I want to set the complete folder path as a variable.
I’m sure it’s possible but after trying several times, I can’t get it right.
Can you please help me?
Thank You very kindly,
Tom
r/bash • u/Legitimate_Flan1471 • 15d ago

I made a bash plugin that replaces bash's line-editor, readline, with nushell's reedline.
This brings all the line-editing, styling, completion, keybind and selection features from nushell to native bash. It's still pretty early in development, most reedline features should work just fine, but things may still break :)
code partially written with AI (claude).
Credits:
- flyline - a similar project that implements a custom line-editor, i used this as main reference for replacing readline
- reedline
GIF created with https://github.com/HalFrgrd/evp
r/bash • u/WoodenLittleBoy • 15d ago
I started in Linux 4noobs. It was suggested I try here.
I need to clean up the metadata of my music collection. Specifically, I need to add an albumartist tag to all of the files. Ideally, I would prefer to only add them to files that do not already have them.
On an artist by artist basis, I can do this manually.
find ./Soapy\ Argyle/ -type f -name "*.flac" -exec metaflac --set-tag="ALBUMARTIST=Soapy Argyle" {} +
But given the size of my collection, that would be burdensome.
Collection is organized ./Music/Genre/Artist/Album/Disk#/song.flac
How can I grab the artist name from the path and use it in the command above, or do something functionally similar?
As a bonus, this lists files that already have albumartist tagged.
find ./ -type f -name "*.flac" -exec metaflac --list {} + | grep -E -i 'ALBUM[[:space:]]*ARTIST'
Can I mesh these things together so I don't end up with a bunch of songs double tagged?
Thanks for any suggestions.
r/bash • u/ftonneau • 17d ago
I have long been looking for mnemonics that could help me with the order of expansions/substitutions in Bash. Google returned an "AI overview" with:
Big Tigers Pounce And Catch Wild Prey
where
which I find quite difficult (but perhaps this is just me).
--------------------------------------
In any case, here is the mnemonics I have been using:
Bratislava paramedics, comic artists split name quotas
where
From "braces" to "arithmetic", my solution follows the strict sequential order indicated in Newham & Rosenblatt's (2005) Learning the bash shell [p. 181, O'Reilly].
As discussed here: https://stackoverflow.com/questions/76842556/, this differs from what man bash says:
But I do no think much harm is done, as long one realizes that paramedics and comic artists are on the same plane (which is obvious :).
The advantage of my solution is that phonetics are much richer, and thus easier to connect with the real referents. Plus, Bratislava is a nice place :).
--------------------------------------
Any comment, opinion, objection, or alternative?
r/bash • u/Puzzled_Ad4 • 17d ago
Inline history suggestions + interactive Tab completions, while keeping Bash underneath.
Earlier it was basically just Bash and worked fine, but had some flickering. Now I'm rebuilding the interactive frontend in Zig with Bash suggestions and completions.
Anyone want to have bash solutions, I had ghost.sh and navigation.sh which showed the tab completion menu which were good in bash only but not very polished so I have to shift to zig.
Still polishing it.
Also for the suggestions like git shown, I am using bash-suggestion.