Is this a good .bashrc file? (Using android termux)
```#!/bin/bash
# Setup
ulimit -u 100 2>/dev/null || echo "Unable to set ulimit."
[ -z "$PS1" ] && return 2>/dev/null
# Vars
PROMPT_COMMAND='now=$(date +%s)'
# Make custom programms folder
mkdir -p $HOME/bin
[[ ":$PATH:" != *":$HOME/bin:"* ]] && export PATH="$PATH:$HOME/bin"
## Aliases
# Remapping
alias clear="clear; source $HOME/.bashrc"
alias bashrc="source $HOME/.bashrc"
# Quick access
alias la="ls -A"
# Permission management
alias enable="chmod +x"
alias disable="chmod -x"
# Full commands
alias cmdlist='printf "\033[7mBuilt-in Commands:\033[0m\n%s\n\n\033[7mExternal Commands:\033[0m\n%s\n" "$(compgen -b)" "$(echo $PATH | tr ":" "\n" | xargs -I {} ls -1 {} 2>/dev/null | sort -u)"'
alias termShare="( set; export; alias ) | sed 's/$/ 2>\/dev\/null/' | tee /dev/tty | termux-clipboard-set 2>/dev/null || printf '\n\033[7mPlease copy the text above.\n'; printf '\n\033[7mNow paste the copied text into the terminal to clone this one into.\033[0m\n'"
# ANSI color codes
reset="\033[0m" #reset
bold="\033[1m" #bold
rev="\033[7m" #invert
r="\033[31m" #red
g="\033[32m" #green
y="\033[33m" #yellow
b="\033[34m" #blue
m="\033[35m" #magenta
c="\033[36m" #cyan
w="\033[37m" #white
# Inital message
printf "${reset}${rev}
,-.
\ \
\ \
/ /,----.
/ / '----'
\`-'
${reset}\n"
printf "Welcome %s\n" "$(whoami 2>/dev/null || echo "?") (${HOSTNAME:-${HOST:-"unknown"}})"
unset reset bold rev r g y b m c w
https://redd.it/1hqefgg
@r_bash
```#!/bin/bash
# Setup
ulimit -u 100 2>/dev/null || echo "Unable to set ulimit."
[ -z "$PS1" ] && return 2>/dev/null
# Vars
PROMPT_COMMAND='now=$(date +%s)'
# Make custom programms folder
mkdir -p $HOME/bin
[[ ":$PATH:" != *":$HOME/bin:"* ]] && export PATH="$PATH:$HOME/bin"
## Aliases
# Remapping
alias clear="clear; source $HOME/.bashrc"
alias bashrc="source $HOME/.bashrc"
# Quick access
alias la="ls -A"
# Permission management
alias enable="chmod +x"
alias disable="chmod -x"
# Full commands
alias cmdlist='printf "\033[7mBuilt-in Commands:\033[0m\n%s\n\n\033[7mExternal Commands:\033[0m\n%s\n" "$(compgen -b)" "$(echo $PATH | tr ":" "\n" | xargs -I {} ls -1 {} 2>/dev/null | sort -u)"'
alias termShare="( set; export; alias ) | sed 's/$/ 2>\/dev\/null/' | tee /dev/tty | termux-clipboard-set 2>/dev/null || printf '\n\033[7mPlease copy the text above.\n'; printf '\n\033[7mNow paste the copied text into the terminal to clone this one into.\033[0m\n'"
# ANSI color codes
reset="\033[0m" #reset
bold="\033[1m" #bold
rev="\033[7m" #invert
r="\033[31m" #red
g="\033[32m" #green
y="\033[33m" #yellow
b="\033[34m" #blue
m="\033[35m" #magenta
c="\033[36m" #cyan
w="\033[37m" #white
# Inital message
printf "${reset}${rev}
,-.
\ \
\ \
/ /,----.
/ / '----'
\`-'
${reset}\n"
printf "Welcome %s\n" "$(whoami 2>/dev/null || echo "?") (${HOSTNAME:-${HOST:-"unknown"}})"
unset reset bold rev r g y b m c w
https://redd.it/1hqefgg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Looking for a corpus of Bash noscripts
I'm looking for a large corpus of open source Bash noscripts; preferably longer noscripts, but that doesn't really matter.
At the moment, I've found:
The `tests` directory in the [Bash repository](https://savannah.gnu.org/git/?group=bash). This is quite large, but it contains a lot of funky stuff for teasing out edge cases:
$ find tests -name "*.tests" -o -name "*.sub" -exec wc -lc --total=only {} \+
19364 467878
[This repository](https://github.com/bensuperpc/noscripts), which was mentioned on this subreddit [about three years ago](https://old.reddit.com/r/bash/comments/ox3sry/collection_of_bash_noscripts/) and contains a lot of quite short, but more "normal" noscripts:
$ find . -name "*.sh" -exec wc -lc --total=only {} \+
12074 400232
The purpose of this is to stress-test formatting engines and to get an idea of throughput.
https://redd.it/1hqey6d
@r_bash
I'm looking for a large corpus of open source Bash noscripts; preferably longer noscripts, but that doesn't really matter.
At the moment, I've found:
The `tests` directory in the [Bash repository](https://savannah.gnu.org/git/?group=bash). This is quite large, but it contains a lot of funky stuff for teasing out edge cases:
$ find tests -name "*.tests" -o -name "*.sub" -exec wc -lc --total=only {} \+
19364 467878
[This repository](https://github.com/bensuperpc/noscripts), which was mentioned on this subreddit [about three years ago](https://old.reddit.com/r/bash/comments/ox3sry/collection_of_bash_noscripts/) and contains a lot of quite short, but more "normal" noscripts:
$ find . -name "*.sh" -exec wc -lc --total=only {} \+
12074 400232
The purpose of this is to stress-test formatting engines and to get an idea of throughput.
https://redd.it/1hqey6d
@r_bash
savannah.gnu.org
The GNU Bourne-Again SHell - Git Repositories [Savannah]
Savannah is a central point for development, distribution
and maintenance of free software, both GNU and non-GNU.
and maintenance of free software, both GNU and non-GNU.
Noob to Bash—Having Trouble Restarting RMM Service via Script, Need Help"
Although I have a workaround, it's not ideal. The workaround is to force the computer to restart once the service stops, but it doesn't always work, and it’s not a reliable solution.
I’m running the bash noscript via an RMM tool where the noscript executes as root. The issue arises when using sudo through the terminal, as the noscript works fine there.
Here’s the command that works when run manually:
sudo launchctl bootout system /Library/LaunchDaemons/com.cenra.cag.plist
sudo launchctl bootstrap system /Library/LaunchDaemons/com.cenra.cag.plist
The challenging part is that the service I'm trying to restart is actually the RMM itself (yes, the RMM is broken, haha).
What I’ve tried so far is running a cron job and saving the noscript in the logged-in user's profile under /Library, then executing it. The noscript is able to bootout the service, but it fails to bootstrap it.
I’ve even attempted to pass temporary admin credentials through the noscript itself.
I know I might be overthinking this, as this is only my second bash noscript. Any help would be greatly appreciated!
https://redd.it/1hqvtxf
@r_bash
Although I have a workaround, it's not ideal. The workaround is to force the computer to restart once the service stops, but it doesn't always work, and it’s not a reliable solution.
I’m running the bash noscript via an RMM tool where the noscript executes as root. The issue arises when using sudo through the terminal, as the noscript works fine there.
Here’s the command that works when run manually:
sudo launchctl bootout system /Library/LaunchDaemons/com.cenra.cag.plist
sudo launchctl bootstrap system /Library/LaunchDaemons/com.cenra.cag.plist
The challenging part is that the service I'm trying to restart is actually the RMM itself (yes, the RMM is broken, haha).
What I’ve tried so far is running a cron job and saving the noscript in the logged-in user's profile under /Library, then executing it. The noscript is able to bootout the service, but it fails to bootstrap it.
I’ve even attempted to pass temporary admin credentials through the noscript itself.
I know I might be overthinking this, as this is only my second bash noscript. Any help would be greatly appreciated!
https://redd.it/1hqvtxf
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
What is X11 related to Bash CLI?
Hi and happy new year there is a new tool github for put the keybindings of trydactyl and similars of vim for linux GUI tools browser, terminal etc but requires x11... I don't know about it....
I have bash in terminal....
what is x11?
https://redd.it/1hr3olj
@r_bash
Hi and happy new year there is a new tool github for put the keybindings of trydactyl and similars of vim for linux GUI tools browser, terminal etc but requires x11... I don't know about it....
I have bash in terminal....
what is x11?
https://redd.it/1hr3olj
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Useful and fun Bash commands
Hi All,
I have created some fun BASH commands including alias
**🚀 Supercharge Your Terminal with These Bash Snippets!**
👋 Hey Reddit! I've packed this GitHub repo with **time-saving noscripts** and **fun terminal hacks** to level up your workflow! 🌟
🔗 **Check it out**: [BashSnippets on GitHub](https://github.com/ParasKoundal/BashSnippets)
# 💻 Highlights:
# 🔥 Git Tools:
* **Beautiful Git History**: Visualize your commits like a pro.
* **Quick Git Commit & Push**: Commit changes in seconds.
* **Auto-pull on** `cd`: Stay synced without thinking.
* **Git Repo Dashboard**: Summarize repo statuses in one command.
# 🎉 Fun Extras:
* **ASCII Art Greetings**: Start your terminal sessions in style!
* **Dynamic Emojis in Prompt**: Add a dash of randomness to your terminal.
* **Deadline Tracker**: Stay on top of projects with real-time updates.
# ⭐️ Show Some Love!
If you enjoy these tools:
1. **Star this repo** ⭐️ to keep me motivated.
2. **Follow me on GitHub** for updates and more cool stuff!
🛠️ **I'm adding new noscripts regularly**, so stay tuned!
https://redd.it/1hrbn86
@r_bash
Hi All,
I have created some fun BASH commands including alias
**🚀 Supercharge Your Terminal with These Bash Snippets!**
👋 Hey Reddit! I've packed this GitHub repo with **time-saving noscripts** and **fun terminal hacks** to level up your workflow! 🌟
🔗 **Check it out**: [BashSnippets on GitHub](https://github.com/ParasKoundal/BashSnippets)
# 💻 Highlights:
# 🔥 Git Tools:
* **Beautiful Git History**: Visualize your commits like a pro.
* **Quick Git Commit & Push**: Commit changes in seconds.
* **Auto-pull on** `cd`: Stay synced without thinking.
* **Git Repo Dashboard**: Summarize repo statuses in one command.
# 🎉 Fun Extras:
* **ASCII Art Greetings**: Start your terminal sessions in style!
* **Dynamic Emojis in Prompt**: Add a dash of randomness to your terminal.
* **Deadline Tracker**: Stay on top of projects with real-time updates.
# ⭐️ Show Some Love!
If you enjoy these tools:
1. **Star this repo** ⭐️ to keep me motivated.
2. **Follow me on GitHub** for updates and more cool stuff!
🛠️ **I'm adding new noscripts regularly**, so stay tuned!
https://redd.it/1hrbn86
@r_bash
GitHub
GitHub - ParasKoundal/BashSnippets: A bunch of bash snippets
A bunch of bash snippets. Contribute to ParasKoundal/BashSnippets development by creating an account on GitHub.
Continuous deployment on LAN/local server upon 'git push' - using webhook & ngrok
Just finished a new bash noscript pforret/landeploy
It helps me setup a local webhook, make it public with ngrok and use it in Github/BitBucket to trigger a redeployment whenever I push a new version. I need this because we have a server at the office with a custom Windows software on it (that we can't run in the cloud), and I need the project to auto-update when we push changes to GitHub. The redeploy noscript runs under WSL.
It is a bash noscript based on the
https://redd.it/1hrdyvb
@r_bash
Just finished a new bash noscript pforret/landeploy
It helps me setup a local webhook, make it public with ngrok and use it in Github/BitBucket to trigger a redeployment whenever I push a new version. I need this because we have a server at the office with a custom Windows software on it (that we can't run in the cloud), and I need the project to auto-update when we push changes to GitHub. The redeploy noscript runs under WSL.
It is a bash noscript based on the
bashew micro framework.https://redd.it/1hrdyvb
@r_bash
GitHub
GitHub - pforret/landeploy: automatic deploy on LAN/localhost upon 'github push'
automatic deploy on LAN/localhost upon 'github push' - pforret/landeploy
why is sleep not working properly?
echoing RANDOM works just fine
and so does sleep
why does it say sleep missing operand?
https://redd.it/1hri7i5
@r_bash
echoing RANDOM works just fine
and so does sleep
why does it say sleep missing operand?
https://redd.it/1hri7i5
@r_bash
Pipe to background process
Hi!
I am trying to write a noscript which opens a connection with psql to PostgreSQL, then issue commands and get their response, multiple times synchronously, then close the background process.
I have got stuck at the part to spawn a background process and keep its stdin and stdout somehow accessible.
I tried this:
Apparently this is not working as fd 4 and fd 5 does not exist.
Should I use mkfifo? I would like to not create any files. Is there a way to open a file denoscriptor without a file, or some other way to approach the problem perhaps?
I am trying to execute this noscript on Mac, so no procfs.
https://redd.it/1hsc6fw
@r_bash
Hi!
I am trying to write a noscript which opens a connection with psql to PostgreSQL, then issue commands and get their response, multiple times synchronously, then close the background process.
I have got stuck at the part to spawn a background process and keep its stdin and stdout somehow accessible.
I tried this:
psql -U user ... >&5 <&4 &
PID=$!
# BEGIN - I would like to issue multiple of these
echo "SELECT now()" >&4
cat <&5
# END
# close psql
kill -SIGTERM $PID
Apparently this is not working as fd 4 and fd 5 does not exist.
Should I use mkfifo? I would like to not create any files. Is there a way to open a file denoscriptor without a file, or some other way to approach the problem perhaps?
I am trying to execute this noscript on Mac, so no procfs.
https://redd.it/1hsc6fw
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How many lines is your bashrc file? Mine is currently 4712 and counting rapidly
I (like many others of you probably) have an addiction of trying to automate every single thing I do and creating bash noscripts for it. Every single tool i make, I put in my bashrc file. Over the course of just 4 months I have gathered 4712 lines of code
At some point it even got to the point where I had to split up the bashrc file in multiple files, and create some sort of framework to create 'composite' commands where i can have one main command and multiple sub-commands like 'profile load' 'profile save' 'profile list'. see example:
alias profile="profile_main_command"
# Composite command
profile_main_command() {
reset_ifs
composite_define_command "profile"
composite_define_subcommand "list"
composite_define_subcommand "current"
composite_define_subcommand "load"
composite_define_subcommand "save"
composite_define_subcommand "edit"
composite_define_subcommand "delete"
composite_handle_subcommand $@
}
This will even automatically make a \`profile help\` command.
All of these tools and handy bash code, i have split up in several bash files, and then I use another bash noscript to combine all of these files together in one big bash file. which is my bashrc.
What about you guys?
https://redd.it/1hshm3u
@r_bash
I (like many others of you probably) have an addiction of trying to automate every single thing I do and creating bash noscripts for it. Every single tool i make, I put in my bashrc file. Over the course of just 4 months I have gathered 4712 lines of code
At some point it even got to the point where I had to split up the bashrc file in multiple files, and create some sort of framework to create 'composite' commands where i can have one main command and multiple sub-commands like 'profile load' 'profile save' 'profile list'. see example:
alias profile="profile_main_command"
# Composite command
profile_main_command() {
reset_ifs
composite_define_command "profile"
composite_define_subcommand "list"
composite_define_subcommand "current"
composite_define_subcommand "load"
composite_define_subcommand "save"
composite_define_subcommand "edit"
composite_define_subcommand "delete"
composite_handle_subcommand $@
}
This will even automatically make a \`profile help\` command.
All of these tools and handy bash code, i have split up in several bash files, and then I use another bash noscript to combine all of these files together in one big bash file. which is my bashrc.
What about you guys?
https://redd.it/1hshm3u
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Bash linting, formatting, etc. tools worth using?
I'm setting up Neovim and typically people set up tools like LSP servers, linting, formatting, etc. to aid in writing code.
Currently I use only use bashls and Neovim diagnostics that rely on shellcheck (still looking for a way for diagnostics to show the relevant code warnings like "SCXXXX" as virtual text so I don't have to manually search up the actual warning and potentially disable it).
Anyone use tools like beautysh, prettier, etc.? Are they as mature as similar tools in other languages? I would like to get a sense of perspective since I don't yet have experience with other "real" programming languages. E.g. maybe such tools aren't as useful for a shell noscripting language and/or the nature of a shell noscripting language is perhaps too opinionated that such tools don't help much.
Any recommendations for tools, however trivial, is much appreciated. I've never used an "industry-standard" code editor like VS Code or a real IDE, so don't know what I might be missing with a barebones Neovim setup.
https://redd.it/1hs0x7g
@r_bash
I'm setting up Neovim and typically people set up tools like LSP servers, linting, formatting, etc. to aid in writing code.
Currently I use only use bashls and Neovim diagnostics that rely on shellcheck (still looking for a way for diagnostics to show the relevant code warnings like "SCXXXX" as virtual text so I don't have to manually search up the actual warning and potentially disable it).
Anyone use tools like beautysh, prettier, etc.? Are they as mature as similar tools in other languages? I would like to get a sense of perspective since I don't yet have experience with other "real" programming languages. E.g. maybe such tools aren't as useful for a shell noscripting language and/or the nature of a shell noscripting language is perhaps too opinionated that such tools don't help much.
Any recommendations for tools, however trivial, is much appreciated. I've never used an "industry-standard" code editor like VS Code or a real IDE, so don't know what I might be missing with a barebones Neovim setup.
https://redd.it/1hs0x7g
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
We developed a simple BASH based CLI installer
It is tailored for our OS, but in theory it should work on any systemd based APT distro. Try https://github.com/armbian/configng
https://redd.it/1hssjme
@r_bash
It is tailored for our OS, but in theory it should work on any systemd based APT distro. Try https://github.com/armbian/configng
https://redd.it/1hssjme
@r_bash
GitHub
GitHub - armbian/configng: armbian-config is a powerful, user-friendly tool that simplifies managing an Armbian system.
armbian-config is a powerful, user-friendly tool that simplifies managing an Armbian system. - armbian/configng
Newbie question regarding #comment within an array of multiple values.
Hello, I have the following code below:
ModEnabled="1" # If 1 = Install/update mods
GameModList="123123123 234234234 345345345"
if $ModEnabled == "1" ;then
printf " ${yellow}REALM-SERVER${default} Updating/Downloading Mod files!\n"
for value in $GameModList; do
${HOME}/servers/steamcmd/steamcmd.sh \
+forceinstalldir ${HOME}/servers/gameserver/ \
+login "${SteamUser}" \
+workshopdownloaditem 123123 "${value}" \
validate +quit
done
printf " ${green}REALM-SERVER${default} Done downloading and updating Mod files!\n"
else
printf " ${red}Error${default} You have not enabled downloading and updating mods, skipping!\n"
fi
However,
GameModList="123123123 234234234 345345345"
Is going to be extremely big soon. My question is basically:
Is it possible do something like this:
GameModList="
123123123 #Mod Denoscription 1
234234234 #Mod Denoscription 2
345345345 #Mod Denoscription 3
"
Basically, list each modID in a new line + adding a #comment?
Best regards, <3
https://redd.it/1hswaqd
@r_bash
Hello, I have the following code below:
ModEnabled="1" # If 1 = Install/update mods
GameModList="123123123 234234234 345345345"
if $ModEnabled == "1" ;then
printf " ${yellow}REALM-SERVER${default} Updating/Downloading Mod files!\n"
for value in $GameModList; do
${HOME}/servers/steamcmd/steamcmd.sh \
+forceinstalldir ${HOME}/servers/gameserver/ \
+login "${SteamUser}" \
+workshopdownloaditem 123123 "${value}" \
validate +quit
done
printf " ${green}REALM-SERVER${default} Done downloading and updating Mod files!\n"
else
printf " ${red}Error${default} You have not enabled downloading and updating mods, skipping!\n"
fi
However,
GameModList="123123123 234234234 345345345"
Is going to be extremely big soon. My question is basically:
Is it possible do something like this:
GameModList="
123123123 #Mod Denoscription 1
234234234 #Mod Denoscription 2
345345345 #Mod Denoscription 3
"
Basically, list each modID in a new line + adding a #comment?
Best regards, <3
https://redd.it/1hswaqd
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
The EveryDay Concerned Citizen | A site to get info, take action, make change happen
https://everydayconcerned.net/
https://redd.it/1hsznsb
@r_bash
https://everydayconcerned.net/
https://redd.it/1hsznsb
@r_bash
The Everyday Concerned Citizen
Media Site & Magazine | Publisher, Editor, Reporter: Ramola D | Independent Investigative Science & Tech/Human Rights/Consciousness Journalism
Is there a way to run an animation in the terminal while still typing commands without ending the animation?
Recently, I got interested in Neofetch (the terminal tool that shows system info in a cool way) and thought it would look so much better if the ASCII art was animated. I searched online but couldn’t find anything that lets you have animations while still using the terminal normally.
https://preview.redd.it/ovwg7912bwae1.png?width=1142&format=png&auto=webp&s=d22cc1e311da1166eb8c35fef426da5e4f7f8be3
I tried some ideas, like messing with the terminal buffer memory and using libraries like
So, my question is: is there any software that can do these two things?
1. Give high control over the terminal in a background process.
2. Let me use normal commands like
If this is a dumb question and the solution is super obvious, feel free to call me out
https://redd.it/1ht5583
@r_bash
Recently, I got interested in Neofetch (the terminal tool that shows system info in a cool way) and thought it would look so much better if the ASCII art was animated. I searched online but couldn’t find anything that lets you have animations while still using the terminal normally.
https://preview.redd.it/ovwg7912bwae1.png?width=1142&format=png&auto=webp&s=d22cc1e311da1166eb8c35fef426da5e4f7f8be3
I tried some ideas, like messing with the terminal buffer memory and using libraries like
ncurses, but they either made the code super complicated to maintain or broke normal terminal usage.So, my question is: is there any software that can do these two things?
1. Give high control over the terminal in a background process.
2. Let me use normal commands like
cd or nvim without visual glitches.If this is a dumb question and the solution is super obvious, feel free to call me out
https://redd.it/1ht5583
@r_bash
how do you splitt(=divide in 2 parts) a pdf using qpdf?
Hi, I am trying to get 2 pdf's of 1 (the original.pdf) for add later some pages in the middle and then I will get 1 again ¿collating? and get the original more big.
I looked online help and found the command splitt but It does a partition of 2 pages groups of the entire pdf, it strepps the pdf.
i need only 1 partition in the pag 45 for example
I found this:
qpdf --split-pages=2 infile.pdf outfile.pdf: output files are outfile-01-02.pdf through outfile-11-12.pdf
from: https://qpdf.readthedocs.io/en/stable/cli.html#option-collate
I hope you understand my question.... and of course if you know later how to get 1 again entired tell me
sorry my not EN lang. here.
Thank you and regards!
https://redd.it/1hteoyw
@r_bash
Hi, I am trying to get 2 pdf's of 1 (the original.pdf) for add later some pages in the middle and then I will get 1 again ¿collating? and get the original more big.
I looked online help and found the command splitt but It does a partition of 2 pages groups of the entire pdf, it strepps the pdf.
i need only 1 partition in the pag 45 for example
I found this:
qpdf --split-pages=2 infile.pdf outfile.pdf: output files are outfile-01-02.pdf through outfile-11-12.pdf
from: https://qpdf.readthedocs.io/en/stable/cli.html#option-collate
I hope you understand my question.... and of course if you know later how to get 1 again entired tell me
sorry my not EN lang. here.
Thank you and regards!
https://redd.it/1hteoyw
@r_bash
Why is this cURL request printing results to the screen?
I'm working on an API for Cloudflare, and I have this (almost straight from the docs):
curl "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?per_page=50000" \
-4 \
--silent \
--header "X-Auth-Email: $email" \
--header "X-Auth-Key: $key" \
| jq -r '.result[].id' \
| while read id
do
curl -4 --request DELETE \
--url "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$id" \
--silent \
--header "X-Auth-Email: $email" \
--header "X-Auth-Key: $key"
done
Here's the doc on it, very short and simple:
[https://developers.cloudflare.com/api/resources/dns/subresources/records/methods/delete/](https://developers.cloudflare.com/api/resources/dns/subresources/records/methods/delete/)
For some reason it's printing this to the screen for each item it deletes:
{"result":{"id":"foo"},"success":true,"errors":[],"messages":[]}
I know that I can just add `> /dev/null 2>&1` to the end of the second curl (inside the while loop) to stop it from printing, but why is it doing it in the first place? None of the other curl statements print to the screen like that.
https://redd.it/1husmzz
@r_bash
I'm working on an API for Cloudflare, and I have this (almost straight from the docs):
curl "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?per_page=50000" \
-4 \
--silent \
--header "X-Auth-Email: $email" \
--header "X-Auth-Key: $key" \
| jq -r '.result[].id' \
| while read id
do
curl -4 --request DELETE \
--url "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$id" \
--silent \
--header "X-Auth-Email: $email" \
--header "X-Auth-Key: $key"
done
Here's the doc on it, very short and simple:
[https://developers.cloudflare.com/api/resources/dns/subresources/records/methods/delete/](https://developers.cloudflare.com/api/resources/dns/subresources/records/methods/delete/)
For some reason it's printing this to the screen for each item it deletes:
{"result":{"id":"foo"},"success":true,"errors":[],"messages":[]}
I know that I can just add `> /dev/null 2>&1` to the end of the second curl (inside the while loop) to stop it from printing, but why is it doing it in the first place? None of the other curl statements print to the screen like that.
https://redd.it/1husmzz
@r_bash
Understanding indirect expansion ( ${!foo} )
I'm having a hard time getting my curl to return an error so that I can test this, so I'm hoping that someone can look at this and tell me if I'm using ${!foo} correctly?
I get the general concept that you use it when the value is used as the name of another variable, so is {!} always used when referencing an array with a variable key?
declare -A dns
# run several curl commands and set the return to a value of the array
dnsfoo=$(curl blahblahblah | jq '.errors | .message')
dnsbar=$(curl blahblahblah | jq '.errors | .message')
dnslorem=$(curl blahblahblah | jq '.errors | .message')
dnsipsum=$(curl blahblahblah | jq '.errors | .message')
# loop through dns and print any error responses
# do I need indirect expansion here?
for key in "${!dns@}";
do
if -n "${!dns[$key}" ]
then
printf "\0330;31m"
printf "DNS '$key' for $domain failed...\n"
printf "${!dns[$key}\n"
printf "\0330m\n"
# clear it so that it doesn't match later
dns[$key=''
fi
done
https://redd.it/1hv9spd
@r_bash
I'm having a hard time getting my curl to return an error so that I can test this, so I'm hoping that someone can look at this and tell me if I'm using ${!foo} correctly?
I get the general concept that you use it when the value is used as the name of another variable, so is {!} always used when referencing an array with a variable key?
declare -A dns
# run several curl commands and set the return to a value of the array
dnsfoo=$(curl blahblahblah | jq '.errors | .message')
dnsbar=$(curl blahblahblah | jq '.errors | .message')
dnslorem=$(curl blahblahblah | jq '.errors | .message')
dnsipsum=$(curl blahblahblah | jq '.errors | .message')
# loop through dns and print any error responses
# do I need indirect expansion here?
for key in "${!dns@}";
do
if -n "${!dns[$key}" ]
then
printf "\0330;31m"
printf "DNS '$key' for $domain failed...\n"
printf "${!dns[$key}\n"
printf "\0330m\n"
# clear it so that it doesn't match later
dns[$key=''
fi
done
https://redd.it/1hv9spd
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Trying to pass a regex via command line, and store it in a variable.
I, for the life of me, can't understand why I can't pass this regex as a variable and use it properly in my shell noscript. I have a text file that contains a number of strings that match a pattern, like this:
ECO "B40"
ECO "E61"
ECO "E63"
If I use grep, such as:
grep "\\"E[6-9\][0-9\]\\"" testdbs/testdb.pgn
It will correctly find all the ECO codes between E60 and E99.
However, If i try to pass "\\"E[6-9\][0-9\]\\"" to a noscript, it all fails.
For example, I'm passing it to the noscript as follows:
./noscript.sh --eco "\"E6-90-9\"" --input testdbs/testdb.pgn
And the noscript picks up the --eco flag via the typical getopts while loop:
case ${opt} in
h )
usage
;;
-)
case "${OPTARG}" in
eco)
ecoregex="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
esac
esac
Later in my noscript, I try to use it like:
while IFS= read -r line; do
if [ "$line" =~ ^"$ecoregex" ]; then
ecomatches="true"
fi
done < $inputfile
But, it doesn't match. It either returns all the strings, or none of them. Any idea what I'm doing wrong?
https://redd.it/1hvjepj
@r_bash
I, for the life of me, can't understand why I can't pass this regex as a variable and use it properly in my shell noscript. I have a text file that contains a number of strings that match a pattern, like this:
ECO "B40"
ECO "E61"
ECO "E63"
If I use grep, such as:
grep "\\"E[6-9\][0-9\]\\"" testdbs/testdb.pgn
It will correctly find all the ECO codes between E60 and E99.
However, If i try to pass "\\"E[6-9\][0-9\]\\"" to a noscript, it all fails.
For example, I'm passing it to the noscript as follows:
./noscript.sh --eco "\"E6-90-9\"" --input testdbs/testdb.pgn
And the noscript picks up the --eco flag via the typical getopts while loop:
case ${opt} in
h )
usage
;;
-)
case "${OPTARG}" in
eco)
ecoregex="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
esac
esac
Later in my noscript, I try to use it like:
while IFS= read -r line; do
if [ "$line" =~ ^"$ecoregex" ]; then
ecomatches="true"
fi
done < $inputfile
But, it doesn't match. It either returns all the strings, or none of them. Any idea what I'm doing wrong?
https://redd.it/1hvjepj
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Passing global variables into other noscripts
Hi everyone, I am working on project, the project has multiple sh files.
main.sh has many global variables i want to share with later running noscripts, first i think of use
I know passing them as arguments is a valid option, but I don't prefer it, because the noscripts i talk about could be written by user "to allow customization"
So to make it easier on user to write his noscript, by source vars.sh, and access all variables, I was thinking about functin like
Which will prints all global variables of the noscript into vars.sh
But i want to make the function generic and work in any noscript, and not hardcode my global variables in the function, so anyone have ideas?
Edit: I forgot to mention that make all global variables to environment variables, but I feel there is a better method than this
https://redd.it/1hvy45h
@r_bash
Hi everyone, I am working on project, the project has multiple sh files.
main.sh has many global variables i want to share with later running noscripts, first i think of use
source main.sh, then i remeber that the variabes values will changed and i will import values before the change.I know passing them as arguments is a valid option, but I don't prefer it, because the noscripts i talk about could be written by user "to allow customization"
So to make it easier on user to write his noscript, by source vars.sh, and access all variables, I was thinking about functin like
__print_my_global_variables "vars.sh"Which will prints all global variables of the noscript into vars.sh
But i want to make the function generic and work in any noscript, and not hardcode my global variables in the function, so anyone have ideas?
Edit: I forgot to mention that make all global variables to environment variables, but I feel there is a better method than this
https://redd.it/1hvy45h
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community