array
if [ $i -eq 0 ]; then
color=$white_bold # First character in the trail is white and bold
fi
if [ $last_pos -ne $trail_pos ]; then
printf "%b" "\033[${trail_pos};${c}H" # Move cursor to the right position
last_pos=$trail_pos
fi
printf "%b" "${color}${trail:$i:1}\033[0m" # Print the character with color
fi
done
positions[$c]=$((pos + 1)) # Update the position for the next cycle
if [ $pos -ge $((ROWS + ${#fade_colors[@]})) ]; then
positions[$c]=0 # Reset position if it moves off screen
trail_chars[$c]=""
fi
done
}
# Main loop for continuous execution of the update_line function
while true; do
update_line
done
# Reset terminal settings on exit (show cursor, clear screen, reset text format)
echo -ne '\033[?25h' # Show cursor
clear
tput sgr0 # Reset text format
​
https://redd.it/1c42aov
@r_bash
if [ $i -eq 0 ]; then
color=$white_bold # First character in the trail is white and bold
fi
if [ $last_pos -ne $trail_pos ]; then
printf "%b" "\033[${trail_pos};${c}H" # Move cursor to the right position
last_pos=$trail_pos
fi
printf "%b" "${color}${trail:$i:1}\033[0m" # Print the character with color
fi
done
positions[$c]=$((pos + 1)) # Update the position for the next cycle
if [ $pos -ge $((ROWS + ${#fade_colors[@]})) ]; then
positions[$c]=0 # Reset position if it moves off screen
trail_chars[$c]=""
fi
done
}
# Main loop for continuous execution of the update_line function
while true; do
update_line
done
# Reset terminal settings on exit (show cursor, clear screen, reset text format)
echo -ne '\033[?25h' # Show cursor
clear
tput sgr0 # Reset text format
​
https://redd.it/1c42aov
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Which characters (keys) are mostly used for bash language?
Looking to buy a new keyboard, so I would like to know if US international layout would be more useful than my primary language.
https://redd.it/1c4277m
@r_bash
Looking to buy a new keyboard, so I would like to know if US international layout would be more useful than my primary language.
https://redd.it/1c4277m
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Piped if-condition always returns true, how to fix?
This code uses a pipe in an if statement condition. Somehow, the condition always is true, even when
Is this because the first command always returns 0? If so, how can I make sure that the condition is only considered
https://redd.it/1c4j8q0
@r_bash
This code uses a pipe in an if statement condition. Somehow, the condition always is true, even when
grep doesn't find anything (aka returning 1).Is this because the first command always returns 0? If so, how can I make sure that the condition is only considered
true when all commands in the pipe return 0?if VBoxManage list hdds | grep --quiet "$VM_NAME"; then
echo "VDI exsists"
else
echo "VDI does not exsist
fi
https://redd.it/1c4j8q0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Patchwork reminder app for bash
The last couple of weeks I refined a super-simple bash noscript starting from a nice `at` example usage.
I wrote more about it here https://blog.carlolobrano.com/posts/2024-04-07-patchwork-reminder-app-bash/
https://redd.it/1c4lpwd
@r_bash
The last couple of weeks I refined a super-simple bash noscript starting from a nice `at` example usage.
I wrote more about it here https://blog.carlolobrano.com/posts/2024-04-07-patchwork-reminder-app-bash/
https://redd.it/1c4lpwd
@r_bash
IT works, for me.
Patchwork Reminder App in Bash
Everybody knows cron jobs, right? But not everybody knows its sibling at.
HELP! Unable to run gcloud on git bash.
I have installed gcloud on my windows system, and its not recognizing the gcloud command somehow.
Its working fine when I am using powershell or CMD. What might be the issue.
One possible reason was the python or node version, but both are corrert
https://redd.it/1c5c8hg
@r_bash
I have installed gcloud on my windows system, and its not recognizing the gcloud command somehow.
Its working fine when I am using powershell or CMD. What might be the issue.
One possible reason was the python or node version, but both are corrert
https://redd.it/1c5c8hg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Share Your Craft.
I want to upgrade my bash noscripting game. Would highly appreciate if you share what kind of noscript to you write for day to day task. So far I am using two noscript to open bunch of file, one for coding related programes, other one for chilling and gaming programe. I have another to download random wallpaper from the internet. What else I should do?
https://redd.it/1c5bwb0
@r_bash
I want to upgrade my bash noscripting game. Would highly appreciate if you share what kind of noscript to you write for day to day task. So far I am using two noscript to open bunch of file, one for coding related programes, other one for chilling and gaming programe. I have another to download random wallpaper from the internet. What else I should do?
https://redd.it/1c5bwb0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Defining a function
Guys can someone please tell me what is the difference between
function main{
}
And
main(){
}
https://redd.it/1c5hmwz
@r_bash
Guys can someone please tell me what is the difference between
function main{
}
And
main(){
}
https://redd.it/1c5hmwz
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Case statement
Does anyone know how to read blank values in case statement. For example
Echo "please enter a number"
Read number
Case $number in
1 ) echo "number is 1" ;;
2 ) echo "number is 2" ;;
*) echo "please enter a number" ;;
esac
What if the user does not input anything.
How do I read that
https://redd.it/1c616ni
@r_bash
Does anyone know how to read blank values in case statement. For example
Echo "please enter a number"
Read number
Case $number in
1 ) echo "number is 1" ;;
2 ) echo "number is 2" ;;
*) echo "please enter a number" ;;
esac
What if the user does not input anything.
How do I read that
https://redd.it/1c616ni
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Help with noscripts run as sudo
i have two noscripts as below, and i usually call the parent one from the terminal.
#!\bin\bash
# $SCRIPTDIR defined here
sudo env PATH="$PATH" "$SCRIPTDIR"/child.sh
wait
# other functions to call here
#!\bin\bash
zypper dup -y
flatpak update -y &
# vencord is in "$HOME"/.local/bin, which is specified in my user's $PATH env var
yes | vencord -install -branch auto &
what i would like to do are:
1 - when i run the parent noscript with
2 - currently when i run the parent noscript, only
what modifications should i make to the noscripts above? many thanks.
https://redd.it/1c6abe6
@r_bash
i have two noscripts as below, and i usually call the parent one from the terminal.
parent.sh#!\bin\bash
# $SCRIPTDIR defined here
sudo env PATH="$PATH" "$SCRIPTDIR"/child.sh
wait
# other functions to call here
child.sh#!\bin\bash
zypper dup -y
flatpak update -y &
# vencord is in "$HOME"/.local/bin, which is specified in my user's $PATH env var
yes | vencord -install -branch auto &
what i would like to do are:
1 - when i run the parent noscript with
-x option, the child one should enable that option as well.2 - currently when i run the parent noscript, only
zypper would print out to stdin. flatpak and vencord should print out to the terminal too.what modifications should i make to the noscripts above? many thanks.
https://redd.it/1c6abe6
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to parse a SQL file with a BASH noscript ?
I need a noscript that will parse a SQL query that contains name and URL that he will then cURL and execute.
https://redd.it/1c6dz5b
@r_bash
I need a noscript that will parse a SQL query that contains name and URL that he will then cURL and execute.
https://redd.it/1c6dz5b
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
What does ;;& in switch case ?
Hello everyone !
I'm pretty new to Bash, I began last week. I'm working on the switch case statement, and on the GNU doc (https://www.gnu.org/software/bash/bash/manual/bash.pdf) on the page 13 of the document (with their count), they talk about the ;;& but I don't understand well what does it do.
Can someone explain it to me please ?
Thank you in advance for your answers.
https://redd.it/1c6he0o
@r_bash
Hello everyone !
I'm pretty new to Bash, I began last week. I'm working on the switch case statement, and on the GNU doc (https://www.gnu.org/software/bash/bash/manual/bash.pdf) on the page 13 of the document (with their count), they talk about the ;;& but I don't understand well what does it do.
Can someone explain it to me please ?
Thank you in advance for your answers.
https://redd.it/1c6he0o
@r_bash
Trying to create shortcut key, combined with fzf.
My intention is to create a shortcut key for bash, when pressed it gives you a list of recently visited directories to chose from, and upon choosing the selected directory the selected directory will be appended to the current cursor point.
I have this achieve almost half way using z command and fzf
z | awk "{print \$2}" | fzf
I'm happy with what this is giving me, but want to initiate this fuzzy search of recently visited directory anytime when I'm typing a command.
Say I have typed cd on my prompt, then initiate the above feature to chose from the list, then chosen option to be appended after the existing cd command.
Can someone shed some lights?
https://redd.it/1c74yjw
@r_bash
My intention is to create a shortcut key for bash, when pressed it gives you a list of recently visited directories to chose from, and upon choosing the selected directory the selected directory will be appended to the current cursor point.
I have this achieve almost half way using z command and fzf
z | awk "{print \$2}" | fzf
I'm happy with what this is giving me, but want to initiate this fuzzy search of recently visited directory anytime when I'm typing a command.
Say I have typed cd on my prompt, then initiate the above feature to chose from the list, then chosen option to be appended after the existing cd command.
Can someone shed some lights?
https://redd.it/1c74yjw
@r_bash
A Bash noscript that adds custom colors to languages in Nano
This bash noscript works on Debian-based OSs and adds color noscripts to your user's $HOME.
Just execute the noscript, open Nano with a shell noscript or whatever language was included, and see the results yourself.
./add-colors-to-nano.sh
You can find the GitHub noscript here.
Cheers guys.
https://redd.it/1c77xb0
@r_bash
This bash noscript works on Debian-based OSs and adds color noscripts to your user's $HOME.
Just execute the noscript, open Nano with a shell noscript or whatever language was included, and see the results yourself.
./add-colors-to-nano.sh
You can find the GitHub noscript here.
Cheers guys.
https://redd.it/1c77xb0
@r_bash
GitHub
noscript-repo/Bash/Misc/System/add-colors-to-nano.sh at main · slyfox1186/noscript-repo
My personal noscript repository with multiple languages supported. AHK v1+v2 | BASH | BATCH | JSON | POWERSHELL | POWERSHELL | PYTHON | WINDOWS REGISTRY | XML - slyfox1186/noscript-repo
I got weriod ENV setting.
RHEL 7.9
When I create new user, the new user always has a env setting DM_HOME.
I checked the /etc/skel/.bashrc, and other files, DM_HOME is not set there.
Where can I find the setting of the env DM_HOME?
Thanks a lot.
BTW, all the existing users have this env when login.
https://redd.it/1c7kdr7
@r_bash
RHEL 7.9
When I create new user, the new user always has a env setting DM_HOME.
I checked the /etc/skel/.bashrc, and other files, DM_HOME is not set there.
Where can I find the setting of the env DM_HOME?
Thanks a lot.
BTW, all the existing users have this env when login.
https://redd.it/1c7kdr7
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
--Base-Path Argument
Good day r/bash,
I have an issue that could be fixed by creating a --base-path argument noscript. Trouble is, I only have a vague idea of what it is, and no clue on how to make one. Seeking explanations, advice, guidance & and any form of documentation on the matter. Thanks !
https://redd.it/1c7nrly
@r_bash
Good day r/bash,
I have an issue that could be fixed by creating a --base-path argument noscript. Trouble is, I only have a vague idea of what it is, and no clue on how to make one. Seeking explanations, advice, guidance & and any form of documentation on the matter. Thanks !
https://redd.it/1c7nrly
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Save command to run as function, array, or string?
I have a while loop and there's one part where it should run either commandA or commandB depending on condition that could already be determined beforehand, therefore I should save the appropriate command into a "variable" that's set before the while loop, e.g. if I were to store the command as an array:
if ...; then
cmd=(do this thing)
else
cmd=(do this other thing)
done
while ...; do
...
# expand variable to run it
"${cmd@}"
...
done
Usually, a function is defined for a command to be re-used but I don't really see defining a function conditionally, i.e.
How do these methods compare? Is there a case to use one over the other? Is one more expensive internally? For readability,
https://redd.it/1c8e8ww
@r_bash
I have a while loop and there's one part where it should run either commandA or commandB depending on condition that could already be determined beforehand, therefore I should save the appropriate command into a "variable" that's set before the while loop, e.g. if I were to store the command as an array:
if ...; then
cmd=(do this thing)
else
cmd=(do this other thing)
done
while ...; do
...
# expand variable to run it
"${cmd@}"
...
done
Usually, a function is defined for a command to be re-used but I don't really see defining a function conditionally, i.e.
cmd() { a... } else cmd() { b... }. And also, if cmd is simply a string, then eval $cmd also works.How do these methods compare? Is there a case to use one over the other? Is one more expensive internally? For readability,
eval might be the most straightforward or least verbose but apparently eval should not be used lightly. Is expanding an array itself that is implicitly(?) executed also considered hacky or at least non-intuitive?https://redd.it/1c8e8ww
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
case statement
what if i use exit instead of break in this case statement when do and cat are selected what are the difference if this was my noscript ?
echo "Please select an animal"
select animal in dog cat; do
case $animal in
dog)
echo "dog selected break"
break ;;
cat)
echo "cat selected"
break ;;
*)
echo "I don't recognize this animal" ;;
esac
done
https://redd.it/1c8n4lt
@r_bash
what if i use exit instead of break in this case statement when do and cat are selected what are the difference if this was my noscript ?
echo "Please select an animal"
select animal in dog cat; do
case $animal in
dog)
echo "dog selected break"
break ;;
cat)
echo "cat selected"
break ;;
*)
echo "I don't recognize this animal" ;;
esac
done
https://redd.it/1c8n4lt
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Can I run my noscript with options ?
I have my noscript, that I want to use it with options. Should I create functions indead of those cases ?
#!/bin/env bash
# Customize Console
PROMPT_COMMAND='echo -en "\033]0;$(FBD|cut -d "/" -f 4-100)\a"'
now=$(date)
echo "Undertale Jokes, that's all. Mainly. You know, as ya want."
while true
do
#Input
VHS=$(gum input --placeholder " Enter Command")
# Treat Input
case $VHS in
exit | q | esc | bye)
exit
;;
clear | cls)
clear
;;
puns | under)
gum pager < ./src/under.txt
;;
nintendo)
gum pager < ./src/nintendo.txt
;;
help)
gum pager < ./doc.md
;;
edit | text | txt | file | editor | nano | vim | vi)
$EDITOR "$(gum file "$FBD")"
;;
issue)
gum log --level info "Report issue at github.com/FBD/issues"
;;
time | date)
gum log --level info "$now"
;;
duck | goose)
gum pager < ./src/duck.txt
;;
annoy | dog)
gum pager < ./src/dog.txt
;;
*)
echo -n "Command not found or not implemented yet."
;;
esac
done
https://redd.it/1c8n90e
@r_bash
I have my noscript, that I want to use it with options. Should I create functions indead of those cases ?
#!/bin/env bash
# Customize Console
PROMPT_COMMAND='echo -en "\033]0;$(FBD|cut -d "/" -f 4-100)\a"'
now=$(date)
echo "Undertale Jokes, that's all. Mainly. You know, as ya want."
while true
do
#Input
VHS=$(gum input --placeholder " Enter Command")
# Treat Input
case $VHS in
exit | q | esc | bye)
exit
;;
clear | cls)
clear
;;
puns | under)
gum pager < ./src/under.txt
;;
nintendo)
gum pager < ./src/nintendo.txt
;;
help)
gum pager < ./doc.md
;;
edit | text | txt | file | editor | nano | vim | vi)
$EDITOR "$(gum file "$FBD")"
;;
issue)
gum log --level info "Report issue at github.com/FBD/issues"
;;
time | date)
gum log --level info "$now"
;;
duck | goose)
gum pager < ./src/duck.txt
;;
annoy | dog)
gum pager < ./src/dog.txt
;;
*)
echo -n "Command not found or not implemented yet."
;;
esac
done
https://redd.it/1c8n90e
@r_bash
Having trouble writing bash noscript to management multiple git repos
Hello everyone, I have multiple git repos, let's say /home/plugin/, /home/core/, /home/tempate/.
I'm trying to write a bash noscript that will run git add . && git commit -m $msg && git push origin main on each of them. However my attempt to use cd to get into the appropriate repo isn't working
#!/bin/bash
read -p 'Message: ' msg
declare -a location=(
"core/"
"plugin/"
"template/"
)
dir=$(pwd)
for var in "${location@}"
do
cd "$dir/$var"
git add .
git commit -m "$msg" .
git push origin main --quiet
done
Can anyone point me in the right direction?
https://redd.it/1c8v0ym
@r_bash
Hello everyone, I have multiple git repos, let's say /home/plugin/, /home/core/, /home/tempate/.
I'm trying to write a bash noscript that will run git add . && git commit -m $msg && git push origin main on each of them. However my attempt to use cd to get into the appropriate repo isn't working
#!/bin/bash
read -p 'Message: ' msg
declare -a location=(
"core/"
"plugin/"
"template/"
)
dir=$(pwd)
for var in "${location@}"
do
cd "$dir/$var"
git add .
git commit -m "$msg" .
git push origin main --quiet
done
Can anyone point me in the right direction?
https://redd.it/1c8v0ym
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to create loop?
create a folder structure for each user, in the first folder create as many folders as uid +1, in each folder with a lower level uid -1 etc.
https://redd.it/1c8wsh0
@r_bash
create a folder structure for each user, in the first folder create as many folders as uid +1, in each folder with a lower level uid -1 etc.
https://redd.it/1c8wsh0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community