bash profiler to measure cost of execuction of commands
I couldn't find or was not satisfied with existing tools for profiling the speed-ness of execution of Bash noscripts, so I decided to write my own. Welcome:
https://github.com/Kamilcuk/L\_bash\_profile
It is "good enough" for me, but could be improved by tracking PIDs of children correctly and with some more documentation and less confusing output. I decided to share it anyway. The
For example, is `sleep 0.1` faster than `sleep 0.2`? Let's make a contrived example.
$ Lbashprofile profile --before 'a() { sleep 0.1; }; b() { sleep 0.2; }' --repeat 10 -o profile.txt 'a;b'
PROFILING: 'a;b' to profile.txt
PROFING ENDED, output in profile.txt
$ Lbashprofile analyze profile.txt
Top 4 cummulatively longest commands:
percent spentus cmd calls spentPerCall topCaller1 topCaller2 topCaller3 example
--------- ---------- --------- ------- -------------- ------------ ------------ ------------ -------------
66.3129 2019599 sleep 0.2 10 201960 b 10 environment:5
33.4767 1019553 sleep 0.1 10 101955 a 10 environment:5
....some more lines...
Well,
Maybe someone will profit from this tool and even motivate me to develop it some further, so I decided to share it. Have fun.
https://redd.it/1hdncbl
@r_bash
I couldn't find or was not satisfied with existing tools for profiling the speed-ness of execution of Bash noscripts, so I decided to write my own. Welcome:
https://github.com/Kamilcuk/L\_bash\_profile
It is "good enough" for me, but could be improved by tracking PIDs of children correctly and with some more documentation and less confusing output. I decided to share it anyway. The
profile subcommand generates profiling information by printing timestamped BASHCOMMAND using DEBUG trap or set -x. Then `analyze` subcommand can analyze the profiling data, subtracting the timestamps, print summary of the most expensive calls, generate a dot callgraph of functions or commands, or similar.For example, is `sleep 0.1` faster than `sleep 0.2`? Let's make a contrived example.
$ Lbashprofile profile --before 'a() { sleep 0.1; }; b() { sleep 0.2; }' --repeat 10 -o profile.txt 'a;b'
PROFILING: 'a;b' to profile.txt
PROFING ENDED, output in profile.txt
$ Lbashprofile analyze profile.txt
Top 4 cummulatively longest commands:
percent spentus cmd calls spentPerCall topCaller1 topCaller2 topCaller3 example
--------- ---------- --------- ------- -------------- ------------ ------------ ------------ -------------
66.3129 2019599 sleep 0.2 10 201960 b 10 environment:5
33.4767 1019553 sleep 0.1 10 101955 a 10 environment:5
....some more lines...
Well,
sleep 0.2 tool 201960 microseconds per call and sleep 0.1 took 101955 microseconds per call, so very suprisingly sleep 0.1 is faster.Maybe someone will profit from this tool and even motivate me to develop it some further, so I decided to share it. Have fun.
https://redd.it/1hdncbl
@r_bash
GitHub
GitHub - Kamilcuk/L_bash_profile: Profile the execution speed of Bash noscripts
Profile the execution speed of Bash noscripts. Contribute to Kamilcuk/L_bash_profile development by creating an account on GitHub.
Inputing bash through a userLAnd terminal is going to make my head explode.
https://redd.it/1hdmspg
@r_bash
https://redd.it/1hdmspg
@r_bash
dLine: command-line productivity tool
If you hate multitasking while you're deep in your IDE, I feel you. I always wanted a calendar that lives right in my terminal - something that can keep track of notes, deadlines, meetings, and events, while also reminding me when something important comes up.
So, I built dLine! 🎉
dLine: command-line productivity tool
It’s a bash noscript that not only manages your schedule but also fetches public and school holidays (only EU countries are supported for now) and even syncs with your Google Calendar. Perfect for keeping your life in check without ever leaving your terminal (IDE).
Check it out and let me know what you think!
https://redd.it/1hdsuaa
@r_bash
If you hate multitasking while you're deep in your IDE, I feel you. I always wanted a calendar that lives right in my terminal - something that can keep track of notes, deadlines, meetings, and events, while also reminding me when something important comes up.
So, I built dLine! 🎉
dLine: command-line productivity tool
It’s a bash noscript that not only manages your schedule but also fetches public and school holidays (only EU countries are supported for now) and even syncs with your Google Calendar. Perfect for keeping your life in check without ever leaving your terminal (IDE).
Check it out and let me know what you think!
https://redd.it/1hdsuaa
@r_bash
GitHub
GitHub - jazz-it/dline: A sleek and simple calendar for terminal enthusiasts.
A sleek and simple calendar for terminal enthusiasts. - jazz-it/dline
Dev Wrap '24 - Spotify Wrapped for Dev's
https://devwrap.thesafezone.xyz
https://redd.it/1heksng
@r_bash
https://devwrap.thesafezone.xyz
https://redd.it/1heksng
@r_bash
devwrap.thesafezone.xyz
v0 App
Created with v0
made my first (actually) bash noscript for first time
I written little bash noscripts before, they we're either just things to start wm and unfinished personal projects that was only for me, so I think I can count that one project as my first actually project that subreddit looked like where I should share it so I'm posting it in here
timecomp.sh: small noscript compare two different command with time command, with nice UI
preview
please tell me if you find something missing in the noscript or if its bad and why. I share it for getting review from other people and improve
(sorry for my bad grammar I'm not good at english)
github repo:https://github.com/LeVeryEpicUsername/timecomp.sh/tree/main
https://redd.it/1herubj
@r_bash
I written little bash noscripts before, they we're either just things to start wm and unfinished personal projects that was only for me, so I think I can count that one project as my first actually project that subreddit looked like where I should share it so I'm posting it in here
timecomp.sh: small noscript compare two different command with time command, with nice UI
preview
please tell me if you find something missing in the noscript or if its bad and why. I share it for getting review from other people and improve
(sorry for my bad grammar I'm not good at english)
github repo:https://github.com/LeVeryEpicUsername/timecomp.sh/tree/main
https://redd.it/1herubj
@r_bash
Apash Library
Hello World,
I would like to share with you a library written in shell noscript (bash/zsh): Apash
Apash provides a readable interface for performing simple operations available in shell noscript like in the other languages.
It is inspired by the Apache commons libraries.
This work leads me to render the interface compatible between shells like bash and zsh (for the moment).
It's relatively easy to contribute with your own snippets.
You can fully install it by following the procedure or just run a container ready to use:
Alternatively, you can use a minified version (just source and forget):
Apash currently includes around 100 methods covering a range of common operations.
I wish that Apash could one day help at least another person around the world.
And if you like it, consider giving it a star, it could help me too.
Depending on your feedbacks, I will continue (or not) to render it compatible with ksh family.
Thank you for all the help you provide there and Happy end of the year !!
https://redd.it/1hffdy1
@r_bash
Hello World,
I would like to share with you a library written in shell noscript (bash/zsh): Apash
Apash provides a readable interface for performing simple operations available in shell noscript like in the other languages.
It is inspired by the Apache commons libraries.
This work leads me to render the interface compatible between shells like bash and zsh (for the moment).
It's relatively easy to contribute with your own snippets.
You can fully install it by following the procedure or just run a container ready to use:
docker run --rm docker.io/hastec/apash:0.2.0-ready 'StringUtils.upperCase "Do or do not, there is no try."'
Alternatively, you can use a minified version (just source and forget):
# Download version for bash
curl "https://raw.githubusercontent.com/hastec-fr/apash/refs/tags/v0.2.0/bin/apash-bash-min.sh" -o apash-bash-min.sh
# Source
. ./apash-bash-min.sh
# Repeat the string
StringUtils.repeat 3 "Ho! "
# result: Ho! Ho! Ho!
Apash currently includes around 100 methods covering a range of common operations.
I wish that Apash could one day help at least another person around the world.
And if you like it, consider giving it a star, it could help me too.
Depending on your feedbacks, I will continue (or not) to render it compatible with ksh family.
Thank you for all the help you provide there and Happy end of the year !!
https://redd.it/1hffdy1
@r_bash
GitHub
GitHub - hastec-fr/apash: Apache's Programs As SHell
Apache's Programs As SHell. Contribute to hastec-fr/apash development by creating an account on GitHub.
Your POV on my app.
Hi, I was wondering whether I should add GUI to my project here or not. It's an app I made which makes managing wine easier, from winehq repositories for enthusiasts like me to install the latest features.
Currently the 4.0 version is in development and adding more features to it.
What's your view on this? Should I do it in shell or Java?
https://redd.it/1hex5e9
@r_bash
Hi, I was wondering whether I should add GUI to my project here or not. It's an app I made which makes managing wine easier, from winehq repositories for enthusiasts like me to install the latest features.
Currently the 4.0 version is in development and adding more features to it.
What's your view on this? Should I do it in shell or Java?
https://redd.it/1hex5e9
@r_bash
GitHub
GitHub - RishonDev/wine-installer
Contribute to RishonDev/wine-installer development by creating an account on GitHub.
Is there a way to delete all files and reset via Bash?
I have a VPS that I can access only via ssh, is there a way to factory reset purely via ssh/bash? Thanks in advance!
https://redd.it/1heider
@r_bash
I have a VPS that I can access only via ssh, is there a way to factory reset purely via ssh/bash? Thanks in advance!
https://redd.it/1heider
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Looking for examples of optimized bash environments for Ansible, Python, Bash development
I'm a fan of utilizing Cygwin for my development and like the feel of running in a CLI vs utilizing something like vscode. I'd like to optimize by bash environment with functions, aliases, etc. I'm looking for examples of useful bash functions or nice bashrc files to optimize development of Python, Ansible (YAML), Bash noscripts, etc.
https://redd.it/1hfwnux
@r_bash
I'm a fan of utilizing Cygwin for my development and like the feel of running in a CLI vs utilizing something like vscode. I'd like to optimize by bash environment with functions, aliases, etc. I'm looking for examples of useful bash functions or nice bashrc files to optimize development of Python, Ansible (YAML), Bash noscripts, etc.
https://redd.it/1hfwnux
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Globbing expansion within variable
I notice this simple noscript behaves differently in bash and zsh
#! /bin/zsh
while read lin
do
echo DEBUG line $lin
done << EOJ
foo * bar
EOJ
In zsh I get the expected output `DEBUG line foo * bar`, but with bash the asterisk is expanded to a list of the files in the current directory. It happens with standard input as well as with HERE documents.
What bash setting could be causing this double evaluation/expansion after assignment, and how do I get similar behavoir to zsh? I do not have any glob or expansion parameter settings in my `.bashrc` so it seems to be a difference with the default bash settings in Ubuntu.
I do not want input text to be interpreted or expanded in any way unless I explicitly use `eval` or `$()`as this is a security risk.
https://redd.it/1hg8crb
@r_bash
I notice this simple noscript behaves differently in bash and zsh
#! /bin/zsh
while read lin
do
echo DEBUG line $lin
done << EOJ
foo * bar
EOJ
In zsh I get the expected output `DEBUG line foo * bar`, but with bash the asterisk is expanded to a list of the files in the current directory. It happens with standard input as well as with HERE documents.
What bash setting could be causing this double evaluation/expansion after assignment, and how do I get similar behavoir to zsh? I do not have any glob or expansion parameter settings in my `.bashrc` so it seems to be a difference with the default bash settings in Ubuntu.
I do not want input text to be interpreted or expanded in any way unless I explicitly use `eval` or `$()`as this is a security risk.
https://redd.it/1hg8crb
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Reflow-safe right-aligned text in terminal via bash?
For styling my PS1, I create a a separator line using ANSI escape codes to create a string of $COLUMNS spaces which is underlined in gray. A simplified form of this would be
PROMPT_COMMAND='PS1=$(printf "\[\033[4;37m%${COLUMNS}s\033[0m\]" " ")"\n\s-\v$ "'
https://preview.redd.it/gdv4df0m3d7e1.png?width=901&format=png&auto=webp&s=1a0d6b7860356d7b2b31dba3a384f3b15fc0c42d
However, this messes up the display when the screen contents get reflowed, e.g. switching from a maximized to a half-screen window. Then I get something awkward like this:
https://preview.redd.it/5dj8l8zh4d7e1.png?width=565&format=png&auto=webp&s=87b998dff60c1bb61c172d2884a3a54f577478b2
https://preview.redd.it/ev36rx2n4d7e1.png?width=901&format=png&auto=webp&s=715dac21d32ac06ef29c5fdd600dd46c09764712
Is it possible to instead genuinely *right-align* a text on the terminal, such that it remains at the right end even if *$COLUMNS* changes? Or, alternatively, is there a way to insert a horizontal line that self-resizes like *<hr>* in HTML?
https://redd.it/1hg5ouj
@r_bash
For styling my PS1, I create a a separator line using ANSI escape codes to create a string of $COLUMNS spaces which is underlined in gray. A simplified form of this would be
PROMPT_COMMAND='PS1=$(printf "\[\033[4;37m%${COLUMNS}s\033[0m\]" " ")"\n\s-\v$ "'
https://preview.redd.it/gdv4df0m3d7e1.png?width=901&format=png&auto=webp&s=1a0d6b7860356d7b2b31dba3a384f3b15fc0c42d
However, this messes up the display when the screen contents get reflowed, e.g. switching from a maximized to a half-screen window. Then I get something awkward like this:
https://preview.redd.it/5dj8l8zh4d7e1.png?width=565&format=png&auto=webp&s=87b998dff60c1bb61c172d2884a3a54f577478b2
https://preview.redd.it/ev36rx2n4d7e1.png?width=901&format=png&auto=webp&s=715dac21d32ac06ef29c5fdd600dd46c09764712
Is it possible to instead genuinely *right-align* a text on the terminal, such that it remains at the right end even if *$COLUMNS* changes? Or, alternatively, is there a way to insert a horizontal line that self-resizes like *<hr>* in HTML?
https://redd.it/1hg5ouj
@r_bash
Matches - A CLI game I coded in Bash
It's based on a two player game that was played in the trenches of World War One.
I made the game as an exercise in learning three new skills with Bash.
YouTube video showing the game being played: https://www.youtube.com/watch?v=24Wrz82JowA
Git Repo to download the game: https://git.zaks.web.za/thisiszeev/matches
Download it, try it out, give me feedback, something something something, profit.
https://redd.it/1hgq6r3
@r_bash
It's based on a two player game that was played in the trenches of World War One.
I made the game as an exercise in learning three new skills with Bash.
YouTube video showing the game being played: https://www.youtube.com/watch?v=24Wrz82JowA
Git Repo to download the game: https://git.zaks.web.za/thisiszeev/matches
Download it, try it out, give me feedback, something something something, profit.
https://redd.it/1hgq6r3
@r_bash
YouTube
Matches - A CLI game I coded in Bash
This game actually originates from the trenches of World War One, except back then they didn't burn the matches to play, each play would instead remove the desired number of matches from a given set.
My Grandfather taught me this game when I was about 5…
My Grandfather taught me this game when I was about 5…
Two different while loops
Is there a functional difference between these two while loops:
find /path/ -type f -name "file.pdf" | while read -r file; do
echo $file
done
while read -r file; do
echo $file
done < <(find /path/ -type f -name "file.pdf")
https://redd.it/1hh3kpt
@r_bash
Is there a functional difference between these two while loops:
find /path/ -type f -name "file.pdf" | while read -r file; do
echo $file
done
while read -r file; do
echo $file
done < <(find /path/ -type f -name "file.pdf")
https://redd.it/1hh3kpt
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
simple bash noscript/syntax help?
Hi there -
I'm looking for help with a fairly simple bash noscript/syntax. (If this isn't the right place, let me know!)
I am trying to write a noscript that will be run frequently (maybe every 10 minutes) in a short mode, but will run a different way (long mode) every 24 hours. (I can create a specific lock file in place so that it will exit if already running).
My thinking is that I can just...
* check for a timestamp file
* If doesn't exist, run **echo $(date) > tmpfile** and run the long mode(assuming this format is adequate)
* if it exists, then pull the date from tmpfile into a variable and if it's < t hours in the past, then run the short mode, otherwise, run it the long mode (and re-seed the tmpfile).
Concept is straightforward, but I just don't know the bash syntax for pulling a date (string) from a file, and doing a datediff in seconds from now, and branching accordingly.
Does anyone have any similar code snippets that could help?
https://redd.it/1hh2wfx
@r_bash
Hi there -
I'm looking for help with a fairly simple bash noscript/syntax. (If this isn't the right place, let me know!)
I am trying to write a noscript that will be run frequently (maybe every 10 minutes) in a short mode, but will run a different way (long mode) every 24 hours. (I can create a specific lock file in place so that it will exit if already running).
My thinking is that I can just...
* check for a timestamp file
* If doesn't exist, run **echo $(date) > tmpfile** and run the long mode(assuming this format is adequate)
* if it exists, then pull the date from tmpfile into a variable and if it's < t hours in the past, then run the short mode, otherwise, run it the long mode (and re-seed the tmpfile).
Concept is straightforward, but I just don't know the bash syntax for pulling a date (string) from a file, and doing a datediff in seconds from now, and branching accordingly.
Does anyone have any similar code snippets that could help?
https://redd.it/1hh2wfx
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
any way I can improve this bash noscript that has double stow command?
stow doesn't delete. It can only throw error or use --adopt to overwrite MY REPO's files instead of overwriting computer files with dotfiles.
I know normal ln can overwrite destination files like this:
but I want to use stow. Current config works decently well but I was wondering if I can replace 2 stow lines with 1?
https://redd.it/1hh740o
@r_bash
stow doesn't delete. It can only throw error or use --adopt to overwrite MY REPO's files instead of overwriting computer files with dotfiles.
I know normal ln can overwrite destination files like this:
ln -sf ~/.dotfiles/alacritty ~/.config/alacritty
but I want to use stow. Current config works decently well but I was wondering if I can replace 2 stow lines with 1?
# this code clones repo, runs install noscript, cd's into that repo, uses stow to distribute files via stow.
# I need to repeat stow twice. First so that if files exist already, those files overwrite
# this git repo files, then I reset this repo and run stow again.
# all this because git stow can't overwrite files / directories if they are already present
git clone --recurse-submodules git@github.com:monoira/.dotfiles.git ~/.dotfiles &&
bash ~/.dotfiles/install_noscripts/_install.sh &&
cd ~/.dotfiles &&
stow -v --adopt alacritty cmus git nvim sqlfluff tmux zsh &&
git add . && git reset --hard &&
stow -v --adopt alacritty cmus git nvim sqlfluff tmux zsh
https://redd.it/1hh740o
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Find files larger than X mb and promp to delete/skip each one found
Hi. I've asked Gemini, Copilot, Claude, etc. for a bash noscript to find files larger than X mb (this should be a parameter to the noscript) starting in the current path, recursively, and then read (prompt) a question to delete or skip each one found.
I've got this:
When executing "./findlargefiles.sh 50", I'm getting an infinite loop of
"Please answer y or n."
Any ideas? I'm trying it on an Ubuntu 22.04 server
Thanks
https://redd.it/1hhtp6g
@r_bash
Hi. I've asked Gemini, Copilot, Claude, etc. for a bash noscript to find files larger than X mb (this should be a parameter to the noscript) starting in the current path, recursively, and then read (prompt) a question to delete or skip each one found.
I've got this:
#!/bin/bashif [ $# -ne 1 ]; thenecho "Usage: $0 <size_in_MB>"exit 1fisize_in_mb=$1find . -type f -size +"${size_in_mb}M" | while IFS= read -r file; do# Get the file sizesize=$(du -h "$file" | cut -f1)echo "File: $file"echo "Size: $size"while true; doread -p "Do you want to delete this file? (y/n): " choicecase "$choice" in[Yy]* )rm "$file"echo "Deleted: $file"break;;[Nn]* )echo "Skipped: $file"break;;* )echo "Please answer y or n.";;esacdonedoneWhen executing "./findlargefiles.sh 50", I'm getting an infinite loop of
"Please answer y or n."
Any ideas? I'm trying it on an Ubuntu 22.04 server
Thanks
https://redd.it/1hhtp6g
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Rate my Ubuntu debloater bash noscript
(I give you permission to steal it)
https://redd.it/1hhw6xe
@r_bash
(I give you permission to steal it)
https://redd.it/1hhw6xe
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Need help understanding and altering a noscript
Hello folks,
I am looking for some help on what this part of a noscript is doing but also alter it to spit out a different output.
p=
This is a part of an Intune macOS noscript that creates a temp admin account and makes a password using the serial number of the device. The problem I am having is that newer macbooks don't contain numbers in their serial! This is conflicting with our password policy that requires a password have atleast 2 numbers and 1 non-alphanumeric.
I understand everything up to the tr and base64. From what I've gathered online, the tr is translating the range of characters, uppercase A to Z and numbers 0 to 9 but I can't get my head around what they're translating to (K-ZA-J and 4-90-3). After this I'm assuming base64 converts the whole thing again to something else.
Any help and suggestions on how to create some numerics out of a character serial would be greatly appreciated.
https://redd.it/1hiiopc
@r_bash
Hello folks,
I am looking for some help on what this part of a noscript is doing but also alter it to spit out a different output.
p=
system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | tr '[A-Z]' '[K-ZA-J]' | tr 0-9 4-90-3 | base64This is a part of an Intune macOS noscript that creates a temp admin account and makes a password using the serial number of the device. The problem I am having is that newer macbooks don't contain numbers in their serial! This is conflicting with our password policy that requires a password have atleast 2 numbers and 1 non-alphanumeric.
I understand everything up to the tr and base64. From what I've gathered online, the tr is translating the range of characters, uppercase A to Z and numbers 0 to 9 but I can't get my head around what they're translating to (K-ZA-J and 4-90-3). After this I'm assuming base64 converts the whole thing again to something else.
Any help and suggestions on how to create some numerics out of a character serial would be greatly appreciated.
https://redd.it/1hiiopc
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Executing a noscript from another noscript programmatically (regardless of run location)
I'm trying to build a simple noscript that will stop my docker containers, drop a volume, then start my containers back up. To start my containers, I have a helper noscript in the root of my project,
Is there a way to essentially do "if subfolder, go up a folder, then run noscript"? If I run the noscript from the root, it'd need to search the current location for the compose noscript. If run from elsewhere, it'd need to go up a level from the noscript's location to find the compose noscript.
I know I can hard code the noscript, but that's inflexible, as if the noscript is moved to another machine, it'd need to be modified. I don't know if my thinking of how to write this noscript is wrong, and would appreciate any feedback.
https://redd.it/1hhbaz2
@r_bash
I'm trying to build a simple noscript that will stop my docker containers, drop a volume, then start my containers back up. To start my containers, I have a helper noscript in the root of my project,
compose.sh. The noscript I'm creating is in a subfolder, noscripts.Is there a way to essentially do "if subfolder, go up a folder, then run noscript"? If I run the noscript from the root, it'd need to search the current location for the compose noscript. If run from elsewhere, it'd need to go up a level from the noscript's location to find the compose noscript.
I know I can hard code the noscript, but that's inflexible, as if the noscript is moved to another machine, it'd need to be modified. I don't know if my thinking of how to write this noscript is wrong, and would appreciate any feedback.
https://redd.it/1hhbaz2
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community