What's your Bash noscript logging setup like?
Do you pipe everything to a file? Use
Would love to see how others handle logging for noscripts that run in the background or via cron.
https://redd.it/1l38wbq
@r_bash
Do you pipe everything to a file? Use
tee? Write your own log function with timestamps? Would love to see how others handle logging for noscripts that run in the background or via cron.
https://redd.it/1l38wbq
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to get an arbitrary integer to align with closest value in array
I have an array that looks like this
I tried doing it in awk and it worked, but i really want to get pure bash solution
https://redd.it/1l38vuw
@r_bash
I have an array that looks like this
array=(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100) and i want to calculate to which value from said array $1 will be closer to, so let's say $1 is 5, i want it to be perceived as 4, and if $1 is 87, i want it to be perceived as 88, and so on. I tried doing it in awk and it worked, but i really want to get pure bash solution
https://redd.it/1l38vuw
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to delete multiple lines only AFTER a search pattern?
I have a file in the standard INI config file structure, so basically
; last modified 1 April 2001 by John Doe
owner
name = John Doe
organization = Acme Widgets Inc.
database
; use IP address in case network name resolution is not working
server = 192.0.2.62
port = 143
file = "payroll.dat"
I want to get rid of all key-value pairs in one specific block, but keep the section header. Number of key-value pairs may be variable, so a fixed line solution wouldn't suffice.
In the example above, the desired replace operation would result in
; last modified 1 April 2001 by John Doe
owner
name = John Doe
organization = Acme Widgets Inc.
database
Any idea how to accomplish this? I tried with
https://redd.it/1l3v0b7
@r_bash
I have a file in the standard INI config file structure, so basically
; last modified 1 April 2001 by John Doe
owner
name = John Doe
organization = Acme Widgets Inc.
database
; use IP address in case network name resolution is not working
server = 192.0.2.62
port = 143
file = "payroll.dat"
I want to get rid of all key-value pairs in one specific block, but keep the section header. Number of key-value pairs may be variable, so a fixed line solution wouldn't suffice.
In the example above, the desired replace operation would result in
; last modified 1 April 2001 by John Doe
owner
name = John Doe
organization = Acme Widgets Inc.
database
Any idea how to accomplish this? I tried with
sed, but I couldn't get it to work.https://redd.it/1l3v0b7
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
BioBASH v0.3.12
https://preview.redd.it/vqfnz6mb955f1.png?width=1320&format=png&auto=webp&s=d4fa3b0e2260c507395add813ff53b70a45ed246
Hey guys this is a "side" project I started as part of my sabbatical leave. Basically is a Suite of tools for bioinformatics written in BASH.
https://github.com/ampinzonv/BB3/wiki
I am sure it has more bugs that i've been able to find, so this is the first time I publish any version, if you find it somehow interesting and are willing to contribute.
Best,
https://redd.it/1l45be3
@r_bash
https://preview.redd.it/vqfnz6mb955f1.png?width=1320&format=png&auto=webp&s=d4fa3b0e2260c507395add813ff53b70a45ed246
Hey guys this is a "side" project I started as part of my sabbatical leave. Basically is a Suite of tools for bioinformatics written in BASH.
https://github.com/ampinzonv/BB3/wiki
I am sure it has more bugs that i've been able to find, so this is the first time I publish any version, if you find it somehow interesting and are willing to contribute.
Best,
https://redd.it/1l45be3
@r_bash
How do I get a variable's value into a file in /sys/?
I want to create a noscript that will automate my battery charge threshold setup. What I used to use was:
sudo tee -a /sys/class/power_supply/BAT0/charge_stop_threshold > /dev/null << 'EOF'
70
EOF
I want to make it user-interactive, which I can do with
I tried replacing all three lines with
How can I take user input and output it into
https://redd.it/1l49hrh
@r_bash
I want to create a noscript that will automate my battery charge threshold setup. What I used to use was:
sudo tee -a /sys/class/power_supply/BAT0/charge_stop_threshold > /dev/null << 'EOF'
70
EOF
I want to make it user-interactive, which I can do with
read -p "enter a percentage: " number. So far I tried replacing 70 with $number and ${number}, which didn't work; $number and ${number} would appear in the file instead of the number I input in temrinal.I tried replacing all three lines with
sudo echo $number > /sys/class/power_supply/BAT0/charge_stop_threshold, but this results in a permission denied error. How can I take user input and output it into
/sys/class/power\_supply/BAT0/charge\_stop\_threshold?https://redd.it/1l49hrh
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How do I speed up this code editing the header information in a FASTA file?
This code is taking too long to run. I'm working with a FASTA file with many thousands of protein accessions ($blastout). I have a file with taxonomy information ("$dir_partial"/lineages.txt). The idea is to loop through all headers, get the accession number and species name in the header, find the corresponding taxonomy lineage in formation, and replace the header with taxonomy information with in-place sed substitution. But it's taking so long.
while read -r line
do
accession="$(echo "$line" | cut -f 1 -d " " | sed 's/>//')"
species="$(echo "$line" | cut -f 2 -d "" | sed 's///')"
taxonomy="$(grep "$species" "$dirpartial"/lineages.txt | head -n 1)"
kingdom="$(echo "$taxonomy" | cut -f 2)"
order="$(echo "$taxonomy" | cut -f 4)"
newname="$(echo "${kingdom}-${order}${species}${accession}" | tr " " "-")"
sed -i "s/>$accession.*/>$newname/" "$dirpartial"/blast-results5000formatted.fasta
done < <(grep ">" "$blastout") # Search headers
Example of original FASTA header:
\>XP_055356955.1 uncharacterized protein LOC129602037 isoform X2 [Paramacrobiotus metropolitanus\]
Example of new FASTA header:
\>Metazoa-Eutardigrada_Paramacrobiotus-metropolitanus_XP_055356955.1
Thanks for your help!
https://redd.it/1l4d9th
@r_bash
This code is taking too long to run. I'm working with a FASTA file with many thousands of protein accessions ($blastout). I have a file with taxonomy information ("$dir_partial"/lineages.txt). The idea is to loop through all headers, get the accession number and species name in the header, find the corresponding taxonomy lineage in formation, and replace the header with taxonomy information with in-place sed substitution. But it's taking so long.
while read -r line
do
accession="$(echo "$line" | cut -f 1 -d " " | sed 's/>//')"
species="$(echo "$line" | cut -f 2 -d "" | sed 's///')"
taxonomy="$(grep "$species" "$dirpartial"/lineages.txt | head -n 1)"
kingdom="$(echo "$taxonomy" | cut -f 2)"
order="$(echo "$taxonomy" | cut -f 4)"
newname="$(echo "${kingdom}-${order}${species}${accession}" | tr " " "-")"
sed -i "s/>$accession.*/>$newname/" "$dirpartial"/blast-results5000formatted.fasta
done < <(grep ">" "$blastout") # Search headers
Example of original FASTA header:
\>XP_055356955.1 uncharacterized protein LOC129602037 isoform X2 [Paramacrobiotus metropolitanus\]
Example of new FASTA header:
\>Metazoa-Eutardigrada_Paramacrobiotus-metropolitanus_XP_055356955.1
Thanks for your help!
https://redd.it/1l4d9th
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How can I speed up this code?
This code is taking too long to run. I'm working with a FASTA file with many thousands of protein accessions ($blastout). I have a file with taxonomy information ("$dir_partial"/lineages.txt). The idea is to loop through all headers, get the accession number and species name in the header, find the corresponding taxonomy lineage in formation, and replace the header with taxonomy information with in-place sed substitution. But it's taking so long.
while read -r line
do
accession="$(echo "$line" | cut -f 1 -d " " | sed 's/>//')"
species="$(echo "$line" | cut -f 2 -d "" | sed 's///')"
taxonomy="$(grep "$species" "$dirpartial"/lineages.txt | head -n 1)"
kingdom="$(echo "$taxonomy" | cut -f 2)"
order="$(echo "$taxonomy" | cut -f 4)"
newname="$(echo "${kingdom}-${order}${species}${accession}" | tr " " "-")"
sed -i "s/>$accession.*/>$newname/" "$dirpartial"/blast-results5000formatted.fasta
done < <(grep ">" "$blastout") # Search headers
Example of original FASTA header:
\>XP_055356955.1 uncharacterized protein LOC129602037 isoform X2 [Paramacrobiotus metropolitanus\]
Example of new FASTA header:
\>Metazoa-Eutardigrada_Paramacrobiotus-metropolitanus_XP_055356955.1
Thanks for your help!
https://redd.it/1l4d8d4
@r_bash
This code is taking too long to run. I'm working with a FASTA file with many thousands of protein accessions ($blastout). I have a file with taxonomy information ("$dir_partial"/lineages.txt). The idea is to loop through all headers, get the accession number and species name in the header, find the corresponding taxonomy lineage in formation, and replace the header with taxonomy information with in-place sed substitution. But it's taking so long.
while read -r line
do
accession="$(echo "$line" | cut -f 1 -d " " | sed 's/>//')"
species="$(echo "$line" | cut -f 2 -d "" | sed 's///')"
taxonomy="$(grep "$species" "$dirpartial"/lineages.txt | head -n 1)"
kingdom="$(echo "$taxonomy" | cut -f 2)"
order="$(echo "$taxonomy" | cut -f 4)"
newname="$(echo "${kingdom}-${order}${species}${accession}" | tr " " "-")"
sed -i "s/>$accession.*/>$newname/" "$dirpartial"/blast-results5000formatted.fasta
done < <(grep ">" "$blastout") # Search headers
Example of original FASTA header:
\>XP_055356955.1 uncharacterized protein LOC129602037 isoform X2 [Paramacrobiotus metropolitanus\]
Example of new FASTA header:
\>Metazoa-Eutardigrada_Paramacrobiotus-metropolitanus_XP_055356955.1
Thanks for your help!
https://redd.it/1l4d8d4
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
help with bash noscript
i have made my nvim configuration and i wanted to do a noscript for installing all the dependencies and things like that, but some of the packages (like lazygit) won't install, can you help me?
since the file is 1402 lines long i will put a link
https://redd.it/1l5xydx
@r_bash
i have made my nvim configuration and i wanted to do a noscript for installing all the dependencies and things like that, but some of the packages (like lazygit) won't install, can you help me?
since the file is 1402 lines long i will put a link
https://redd.it/1l5xydx
@r_bash
GitHub
NVIM-configuration/installation.sh at master · Sckab/NVIM-configuration
This is my personal configuration of Neovim. I tried to make it as modular as possible. I've gone with a black and green color scheme, which I think looks pretty good. For the best appearan...
Cybersecurity, AI and MacOS Learning plan - Thoughts?
Hey everyone! I’m on week 2 of a 12-week, plan of expanding my knowledge in Cybersecurity, AI, Bash and MacOS. **I’m looking for:**
* Suggestions on improving my shell noscripts or aliases
* Best practices for file permissions, Git workflows, and CI/CD in a security context
* Recommendations for next challenges (CTFs, labs, or open-source tools)
I am a beginner and **so far I learnt:**
* Basic Bash/Terminal/iTerm2 and Visual Studio - focused on getting very basics first
* Created a Repo to share all learnings and files
* Completed OverTheWire Bandit levels 0–6 - using it to reinforce point 1.
* Kept detailed notes and screenshots of my terminal work
**I’m looking for:**
* Suggestions on improving my shell noscripts or aliases
* Best practices for file permissions, Git workflows, and CI/CD in a security context
* Recommendations for next challenges (CTFs, labs, or open-source tools)
* Friendly feedback the plan and how my repo is looking :)
**Check out my repo & plan:**
[https://github.com/birdhale/secai-module1](https://github.com/birdhale/secai-module1)
Any insights, critiques, or pointers are welcomed!
https://redd.it/1l625np
@r_bash
Hey everyone! I’m on week 2 of a 12-week, plan of expanding my knowledge in Cybersecurity, AI, Bash and MacOS. **I’m looking for:**
* Suggestions on improving my shell noscripts or aliases
* Best practices for file permissions, Git workflows, and CI/CD in a security context
* Recommendations for next challenges (CTFs, labs, or open-source tools)
I am a beginner and **so far I learnt:**
* Basic Bash/Terminal/iTerm2 and Visual Studio - focused on getting very basics first
* Created a Repo to share all learnings and files
* Completed OverTheWire Bandit levels 0–6 - using it to reinforce point 1.
* Kept detailed notes and screenshots of my terminal work
**I’m looking for:**
* Suggestions on improving my shell noscripts or aliases
* Best practices for file permissions, Git workflows, and CI/CD in a security context
* Recommendations for next challenges (CTFs, labs, or open-source tools)
* Friendly feedback the plan and how my repo is looking :)
**Check out my repo & plan:**
[https://github.com/birdhale/secai-module1](https://github.com/birdhale/secai-module1)
Any insights, critiques, or pointers are welcomed!
https://redd.it/1l625np
@r_bash
GitHub
GitHub - birdhale/secai-module1
Contribute to birdhale/secai-module1 development by creating an account on GitHub.
CD shortcut
Is there a way i can put a cd command to go to the desktop in a shell noscript so i can do it without having to type "cd" capital "D", "esktop". Thanks
https://redd.it/1l69apz
@r_bash
Is there a way i can put a cd command to go to the desktop in a shell noscript so i can do it without having to type "cd" capital "D", "esktop". Thanks
https://redd.it/1l69apz
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
I made a bashrc noscriptlet to make the `cd` command switch your working directory to ~/Desktop.
https://github.com/brlin-tw/cd-to-desktop
https://redd.it/1l6f4av
@r_bash
https://github.com/brlin-tw/cd-to-desktop
https://redd.it/1l6f4av
@r_bash
GitHub
GitHub - brlin-tw/cd-to-desktop: A fun (and highly unnecessary) hack to make the Bash shell's built-in `cd` command change the…
A fun (and highly unnecessary) hack to make the Bash shell's built-in `cd` command change the working directory to the user's Desktop folder by default. - brlin-tw/cd-to-desktop
Has anyone ever used /usr/bin/factor in a noscript?
Just discovered this command. Since it's part of coreutils I assume it has its uses. But has anyone ever used it in a noscript?
https://redd.it/1l6p0dp
@r_bash
Just discovered this command. Since it's part of coreutils I assume it has its uses. But has anyone ever used it in a noscript?
https://redd.it/1l6p0dp
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
sshm (SSHMenu) – Interactive, SSH Host Selector for Bash
Hey r/Bash! 👋
I’ve just published a tiny but mighty Bash noscript called **sshm.sh** that turns your
Out of all the noscripts I have written, this is the one I use the most. It is a single file that works on both macOS and Linux. It is a great way to quickly SSH into servers without having to remember their hostnames or IP addresses.
- Note: Windows support isn’t implemented yet, but it should be pretty flexible and easy to add. If anyone’s interested in contributing and helping out with that, I’d really appreciate it!
# 📂 Example ~/.ssh/config
textCopyEditHost production
HostName prod.example.com
User deploy
Port 22
Host staging
HostName stage.example.com
User deploy
Port 2222
Host myserver
HostName 192.168.1.42
User BASH
Port 1234
Running
Select a server to SSH into:
1) Root-Centos7-Linux 4) Root-MacbookPro 7) Kali-Linux
2) Root-Kali-Linux 5) Root-Rocky-Linux 8) MacbookPro-MeshNet
3) Rocky-Linux 6) MacbookPro 9) Centos7-Linux
Server #: <number>
https://redd.it/1l6vin0
@r_bash
Hey r/Bash! 👋
I’ve just published a tiny but mighty Bash noscript called **sshm.sh** that turns your
~/.ssh/config into an interactive SSH menu. If you regularly SSH into multiple hosts, this lets you pick your target by number instead of typing out long hostnames every time.Out of all the noscripts I have written, this is the one I use the most. It is a single file that works on both macOS and Linux. It is a great way to quickly SSH into servers without having to remember their hostnames or IP addresses.
- Note: Windows support isn’t implemented yet, but it should be pretty flexible and easy to add. If anyone’s interested in contributing and helping out with that, I’d really appreciate it!
# 📂 Example ~/.ssh/config
textCopyEditHost production
HostName prod.example.com
User deploy
Port 22
Host staging
HostName stage.example.com
User deploy
Port 2222
Host myserver
HostName 192.168.1.42
User BASH
Port 1234
Running
./sshm.sh then shows:Select a server to SSH into:
1) Root-Centos7-Linux 4) Root-MacbookPro 7) Kali-Linux
2) Root-Kali-Linux 5) Root-Rocky-Linux 8) MacbookPro-MeshNet
3) Rocky-Linux 6) MacbookPro 9) Centos7-Linux
Server #: <number>
https://redd.it/1l6vin0
@r_bash
GitHub
GitHub - yousefabuz17/SSHMenu: A standalone Bash noscript providing an interactive SSH menu for connecting to hosts defined in your…
A standalone Bash noscript providing an interactive SSH menu for connecting to hosts defined in your `~/.ssh/config`. - yousefabuz17/SSHMenu
Better ip --brief
https://preview.redd.it/ao1lfoqxmy5f1.png?width=894&format=png&auto=webp&s=de481dbb7b37e53ffe31faadec25586d792a3f32
alias obscureIPv6='sed -E "s|m[23][0-9a-f]{3}:[0-9a-f]{1,4}:([^/]*?)/|m3fff:abc:\1/|g"'
function tracepath {
/usr/sbin/tracepath $@ | obscureIPv6
}
function ip {
/usr/sbin/ip -h -s --color=always $@ | obscureIPv6
}
alias obscureIPv6='sed -E "s|m[23][0-9a-f]{3}:[0-9a-f]{1,4}:([^/]*?)/|m3fff:abc:\1/|g"'
function tracepath {
/usr/sbin/tracepath $@ | obscureIPv6
}
function ip {
/usr/sbin/ip -h -s --color=always $@ | obscureIPv6
}
┌ sebastian@suse:0 ~/.bashrc.d ✔ (master)
└ $ cat 99-ip
function ipbrief {
/usr/sbin/ip --brief -h -s "$@" | \
awk '
BEGIN {# Farbcodes
r = "\033[31m" # rot
g = "\033[32m" # grün
y = "\033[33m" # gelb
reset = "\033[0m"}
NF == 0 { next } # Skip empty lines
{
# Routing Table
if ($1 ~ /[.]/) { # IPv4
printf("%s%-30s%s", g, $1, reset)
} else if ($1 ~ /[:]/) { # IPv6
printf("%s%-30s%s", y, $1, reset)
} else if ($1 ~ /default/) { # default route
printf("%s%-30s%s", r, $1, reset)
} else if ($1 ~ /unreachable/ ) { # for now drop unreachable routes
next
}
if ($2 ~ /via/) {
if ($3 ~ /[.]/) { # IPv4
printf("→ %s%-30s%s | %-15s\n", g, $3, reset, $5)
} else if ($3 ~ /[:]/) { # IPv6
printf("→ %s%-30s%s | %-15s\n", y, $3, reset, $5)
} else {
printf("→ %-30s | %-15s\n", $3, $5)
}
next
} else if ($2 ~ /dev/) {
printf("→ %s%-30s%s | %-15s\n", r, $3, reset, $5)
next
}
# Interface name, state, first address
if ($2 ~ "UP") {
printf("%-20s %s%-9s%s", $1, g, $2, reset)
} else if ($2 ~ "DOWN") {
printf("%-20s %s%-9s%s", $1, r, $2, reset)
} else {
printf("%-20s %-9s", $1, $2, $3)
}
# addresses
for (i = 3; i <= NF; i++) {
# skip metrics
if ($i == "metric") {
i++;
continue
}
# indentation
if (i > 3) {printf("%30s", "")}
if ($i ~ /\./) { # IPv4
printf("%s%-20s%s\n", g, $i, reset)
} else if ($i ~ /:/) { # IPv6 | MAC
printf("%s%-20s%s\n", y, $i, reset)
} else if ($i ~ /<.*?>/) { # additional link information
printf("→ %-20s\n", $i)
} else {
printf("\n")
}
}
# if no address is configured print newline
if (NF < 3) {printf("\n")}
}' | obscureIPv6
}
https://redd.it/1l7fb0g
@r_bash
https://preview.redd.it/ao1lfoqxmy5f1.png?width=894&format=png&auto=webp&s=de481dbb7b37e53ffe31faadec25586d792a3f32
alias obscureIPv6='sed -E "s|m[23][0-9a-f]{3}:[0-9a-f]{1,4}:([^/]*?)/|m3fff:abc:\1/|g"'
function tracepath {
/usr/sbin/tracepath $@ | obscureIPv6
}
function ip {
/usr/sbin/ip -h -s --color=always $@ | obscureIPv6
}
alias obscureIPv6='sed -E "s|m[23][0-9a-f]{3}:[0-9a-f]{1,4}:([^/]*?)/|m3fff:abc:\1/|g"'
function tracepath {
/usr/sbin/tracepath $@ | obscureIPv6
}
function ip {
/usr/sbin/ip -h -s --color=always $@ | obscureIPv6
}
┌ sebastian@suse:0 ~/.bashrc.d ✔ (master)
└ $ cat 99-ip
function ipbrief {
/usr/sbin/ip --brief -h -s "$@" | \
awk '
BEGIN {# Farbcodes
r = "\033[31m" # rot
g = "\033[32m" # grün
y = "\033[33m" # gelb
reset = "\033[0m"}
NF == 0 { next } # Skip empty lines
{
# Routing Table
if ($1 ~ /[.]/) { # IPv4
printf("%s%-30s%s", g, $1, reset)
} else if ($1 ~ /[:]/) { # IPv6
printf("%s%-30s%s", y, $1, reset)
} else if ($1 ~ /default/) { # default route
printf("%s%-30s%s", r, $1, reset)
} else if ($1 ~ /unreachable/ ) { # for now drop unreachable routes
next
}
if ($2 ~ /via/) {
if ($3 ~ /[.]/) { # IPv4
printf("→ %s%-30s%s | %-15s\n", g, $3, reset, $5)
} else if ($3 ~ /[:]/) { # IPv6
printf("→ %s%-30s%s | %-15s\n", y, $3, reset, $5)
} else {
printf("→ %-30s | %-15s\n", $3, $5)
}
next
} else if ($2 ~ /dev/) {
printf("→ %s%-30s%s | %-15s\n", r, $3, reset, $5)
next
}
# Interface name, state, first address
if ($2 ~ "UP") {
printf("%-20s %s%-9s%s", $1, g, $2, reset)
} else if ($2 ~ "DOWN") {
printf("%-20s %s%-9s%s", $1, r, $2, reset)
} else {
printf("%-20s %-9s", $1, $2, $3)
}
# addresses
for (i = 3; i <= NF; i++) {
# skip metrics
if ($i == "metric") {
i++;
continue
}
# indentation
if (i > 3) {printf("%30s", "")}
if ($i ~ /\./) { # IPv4
printf("%s%-20s%s\n", g, $i, reset)
} else if ($i ~ /:/) { # IPv6 | MAC
printf("%s%-20s%s\n", y, $i, reset)
} else if ($i ~ /<.*?>/) { # additional link information
printf("→ %-20s\n", $i)
} else {
printf("\n")
}
}
# if no address is configured print newline
if (NF < 3) {printf("\n")}
}' | obscureIPv6
}
https://redd.it/1l7fb0g
@r_bash
My Personal Bash Style Guide
Hey everyone, I wrote this \~10 years ago but i recently got around to making its own dedicated website for it. You can view it in your browser at style.ysap.sh or you can render it in your terminal with:
curl style.ysap.sh
It's definitely opionated and I don't expect everyone to agree on the aesthetics of it haha, but I think the bulk of it is good for avoiding pitfalls and some useful tricks when noscripting.
The source is hosted on GitHub and it's linked on the website - alternative versions are avaliable with:
curl style.ysap.sh/plain # no coloring
curl style.ysap.sh/md # raw markdown
so render it however you'd like.
For bonus points the whole website is rendered itself using bash. In the source cod you'll find noscripts to convert Markdown to ANSI and another to convert ANSI to HTML.
https://redd.it/1l7kr1r
@r_bash
Hey everyone, I wrote this \~10 years ago but i recently got around to making its own dedicated website for it. You can view it in your browser at style.ysap.sh or you can render it in your terminal with:
curl style.ysap.sh
It's definitely opionated and I don't expect everyone to agree on the aesthetics of it haha, but I think the bulk of it is good for avoiding pitfalls and some useful tricks when noscripting.
The source is hosted on GitHub and it's linked on the website - alternative versions are avaliable with:
curl style.ysap.sh/plain # no coloring
curl style.ysap.sh/md # raw markdown
so render it however you'd like.
For bonus points the whole website is rendered itself using bash. In the source cod you'll find noscripts to convert Markdown to ANSI and another to convert ANSI to HTML.
https://redd.it/1l7kr1r
@r_bash
Dotfiles Are the New Tattoos: What Your ~/.bashrc Says About You
https://gizvault.com/archives/dotfile-are-the-new-tattoos
https://redd.it/1l7k1ti
@r_bash
https://gizvault.com/archives/dotfile-are-the-new-tattoos
https://redd.it/1l7k1ti
@r_bash
Gizvault
Dotfiles Are the New Tattoos: What Your ~/.bashrc Says About You
Explore our cyberpunk-inspired e-commerce store, where tech enthusiasts and geeks can discover unique products that blend retro aesthetics with cutting-edge technology. Get your hands on the coolest gadgets and gear, handpicked for those who love to tinker…
Using command separators (&&, ||) and here documents
I was messing around with for too long and thought I'd share a couple of ways to make this work (without
# 1 ) Put the command separator (&&, ||, or ;) AFTER the DECLARATION of the here document delimiter
#!/bin/bash
true &&
true &&
cat > ./my-conf.yml <<-EOF && # <-- COMMAND SEPARATOR GOES HERE
host: myhost.example.com
... blah blah ...
EOF
true &&
true
# 2 ) Put the command with the here document into a "group" by itself
#!/bin/bash
set -e
set -x
true &&
true &&
{ cat > my-conf.yml <<-EOF # <--- N.B.: MUST PUT A SPACE AFTER THE CURLY BRACE
host: myhost.example.com
... blah blah ...
EOF
} && # <--- COMMAND SEPARATOR GOES HERE
true &&
true
I tested this with a lot of different combinations of "true" and "false" as the commands, &&, ||, and ; as separators, and crashing the cat command with a bad directory. They all seemed to continue or stop execution as expected.
https://redd.it/1l7p50o
@r_bash
I was messing around with for too long and thought I'd share a couple of ways to make this work (without
set -e).# 1 ) Put the command separator (&&, ||, or ;) AFTER the DECLARATION of the here document delimiter
#!/bin/bash
true &&
true &&
cat > ./my-conf.yml <<-EOF && # <-- COMMAND SEPARATOR GOES HERE
host: myhost.example.com
... blah blah ...
EOF
true &&
true
# 2 ) Put the command with the here document into a "group" by itself
#!/bin/bash
set -e
set -x
true &&
true &&
{ cat > my-conf.yml <<-EOF # <--- N.B.: MUST PUT A SPACE AFTER THE CURLY BRACE
host: myhost.example.com
... blah blah ...
EOF
} && # <--- COMMAND SEPARATOR GOES HERE
true &&
true
I tested this with a lot of different combinations of "true" and "false" as the commands, &&, ||, and ; as separators, and crashing the cat command with a bad directory. They all seemed to continue or stop execution as expected.
https://redd.it/1l7p50o
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Sleep behaviour in suspension
I can't find a clear answer for this anywhere so I will be asking it here.
I want to write a simple noscript that randomly rotates my wallpaper using waypaper every hour with a simple infinite loop, as follows:
while :
do
sleep 3600
waypaper --random
done
# not even sure if this is the cleanest way to do this, I'm a noob
I can't find a clear answer for suspension behavior, however.
My system suspends after 30 minutes. Say it suspended exactly 30 minutes after the sleep timer started. If my computer doesn't wake up for an hour after suspension (1 hour, 30 minutes after sleep started) and comes back, will the sleep command continue from 30 minutes (where it left off), or calculate the time after suspension begin, run waypaper --random, and skip another 30 minutes. Or would it just skip to 0, run the waypaper command, and restart the timer?
I know I could just test it out with echo commands but it's much easier to ask someone knowledgeable. Thanks!
https://redd.it/1l762qu
@r_bash
I can't find a clear answer for this anywhere so I will be asking it here.
I want to write a simple noscript that randomly rotates my wallpaper using waypaper every hour with a simple infinite loop, as follows:
while :
do
sleep 3600
waypaper --random
done
# not even sure if this is the cleanest way to do this, I'm a noob
I can't find a clear answer for suspension behavior, however.
My system suspends after 30 minutes. Say it suspended exactly 30 minutes after the sleep timer started. If my computer doesn't wake up for an hour after suspension (1 hour, 30 minutes after sleep started) and comes back, will the sleep command continue from 30 minutes (where it left off), or calculate the time after suspension begin, run waypaper --random, and skip another 30 minutes. Or would it just skip to 0, run the waypaper command, and restart the timer?
I know I could just test it out with echo commands but it's much easier to ask someone knowledgeable. Thanks!
https://redd.it/1l762qu
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Just released: bashunit 0.20.0
https://github.com/TypedDevs/bashunit/releases/tag/0.20.0
https://redd.it/1l72xcu
@r_bash
https://github.com/TypedDevs/bashunit/releases/tag/0.20.0
https://redd.it/1l72xcu
@r_bash
GitHub
Release 0.20.0 · TypedDevs/bashunit
🔖 What's Changed
🥇 New Features
Added assert_not_called to ensure a test double has not been invoked #410
Introduced assert_match_snapshot_ignore_colors to support color-insensitive snapshot c...
🥇 New Features
Added assert_not_called to ensure a test double has not been invoked #410
Introduced assert_match_snapshot_ignore_colors to support color-insensitive snapshot c...
cat file | head fails, when using "strict mode"
I use "strict mode" since several weeks. Up to now this was a positive experience.
But I do not understand this. It fails if I use `cat`.
```
#!/bin/bash
trap 'echo "ERROR: A command has failed. Exiting the noscript. Line was ($0:$LINENO): $(sed -n "${LINENO}p" "$0")"; exit 3' ERR
set -Eeuo pipefail
set -x
du -a /etc >/tmp/etc-files 2>/dev/null || true
ls -lh /tmp/etc-files
# works (without cat)
head -n 10 >/tmp/disk-usage-top-10.txt </tmp/etc-files
# fails (with cat)
cat /tmp/etc-files | head -n 10 >/tmp/disk-usage-top-10.txt
echo "done"
```
Can someone explain that?
> GNU bash, Version 5.2.26(1)-release (x86_64-pc-linux-gnu)
https://redd.it/1l8tjbx
@r_bash
I use "strict mode" since several weeks. Up to now this was a positive experience.
But I do not understand this. It fails if I use `cat`.
```
#!/bin/bash
trap 'echo "ERROR: A command has failed. Exiting the noscript. Line was ($0:$LINENO): $(sed -n "${LINENO}p" "$0")"; exit 3' ERR
set -Eeuo pipefail
set -x
du -a /etc >/tmp/etc-files 2>/dev/null || true
ls -lh /tmp/etc-files
# works (without cat)
head -n 10 >/tmp/disk-usage-top-10.txt </tmp/etc-files
# fails (with cat)
cat /tmp/etc-files | head -n 10 >/tmp/disk-usage-top-10.txt
echo "done"
```
Can someone explain that?
> GNU bash, Version 5.2.26(1)-release (x86_64-pc-linux-gnu)
https://redd.it/1l8tjbx
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community