r_bash | Unsorted

Telegram-канал r_bash - r_bash

36

Credits: @r_channels & @reddit2telegram

Subscribe to a channel

r_bash

"done"

echo

for i in *
do
if [ -f "$i" ]
then
echo -e "\033[34m$i\033[0m"
elif [ -d "$i" ]
then
echo -e "\033[32;4m$i\033[0m"
cd "$i"

for j in *
do
if [ -f "$j" ]
then
echo -e "\t\033[34m$j\033[0m"
elif [ -d "$j" ]
then
echo -e "\t\033[32;4m$j\033[0m"
fi
done
echo
cd ..
fi

done

echo


https://redd.it/1hz5ec8
@r_bash

Читать полностью…

r_bash

A script for renaming movie files

Most of the time, when you get a movie file it's a directory containing the video file, maybe some subtitles, and a bunch of other junk files. The names of the files are usually crowded and unreadable. I used to rename them all myself, but I got tired of it, so I learned how to write shell scripts.

[stripper.sh](http://stripper.sh) is really useful tool, and it has saved me a huge amount of work over the last few years. It is designed to operate on a directory containing one or many subdirectories, each one containing a different movie. It formats the names of the subdirectories and the files in them and deletes extra junk files. This script is dependent on "rename," which is really worth getting, it's another huge time saver.

It has four options which can be used individually or together:

1. Option p: Convert periods and underscores to spaces
2. Option t: Trim directory names after title and year
3. Option s: Search and remove a pattern/string from directory and file names
4. Option m: Match file names to the names of their parent directories
5. No option or any other letter entered: Shows the user guide.

Here is an example working directory before running stripper.sh:

Cold.Blue.Steel.1988.1080p.s3cr3t.0ri0le.6xV_HAYT_
↳Cold.Blue.Steel.1988.1080p.s3cr3t.0ri0le.6xV_HAYT_.mkv
poster.JPG
english.srt
info.nfo
other torrents.txt

Angel Feather [1996] 720p_an0rtymous_2200
↳Angel Feather [1996] 720p_an0rtymous_2200.mp4
english [SDH].srt
screenshot128620.png
screenshot186855.png
screenshot209723.png
readme.txt
susfile.exe

...and after running [stripper.sh](http://stripper.sh) \-ptm:

Cold Blue Steel (1988)
↳Cold Blue Steel (1988).mkv
Cold Blue Steel (1988).eng.srt

Angel Feather (1996)
↳Angel Feather (1996).mp4
Angel Feather (1996).eng.srt

It's not perfect, there are some limitations, mainly if there are sub-subdirectories. Sometimes there are, with subtitle files or screenshots. The script does not handle those, but it does not delete them either.

Here is the code: (I'm sorry if the indents are screwed up, reddit removed them from one of the sections, don't ask me why)

#!/bin/bash

OPT=$1

#----------------Show user guide

if [ -z "$OPT" ] || [ `echo "$OPT" | grep -Ev [ptsm]` ]
then
echo -e "\033[38;5;138m\033[1mUSAGE: \033[0m"
echo -e "\t\033[38;5;138m\033[1mstripper.sh\033[0m [\033[4mOPTIONS\033[0m]\n"
echo -e "\033[38;5;138m\033[1mOPTIONS\033[0m"
echo -e "\tPick one or more, no spaces between. Operations take place in the order below."
echo -e "\n\t\033[38;5;138m\033[1mp\033[0m\tConvert periods and underscores to spaces in file and directory names."
echo -e "\n\t\033[38;5;138m\033[1ms\033[0m\tSearch and remove pattern from file and directory names."
echo -e "\n\t\033[38;5;138m\033[1mt\033[0m\tTrim directory names after title and year."
echo -e "\n\t\033[38;5;138m\033[1mm\033[0m\tMatch filenames to parent directory names.\n"

exit 0
fi

#-----------------Make periods and underscores into spaces

if echo "$OPT" | grep -q 'p'
then
echo -n "Converting underscores and periods to spaces... "

for j in *
do

if [ -d "$j" ]
then
rename -E 's/\_/\ /g' -E 's/\./\ /g' "$j"
elif [ -f "$j" ]
then
rename -E 's/\_/\ /g' -E 's/\./\ /g' -E 's/ (...)$/.$1/' "$j"
fi

done

echo "done"
fi

#---------------Search and destroy

if echo "$OPT" | grep -q 's'
then
echo "Remove search pattern from filenames:"
echo "Show file/directory list? y/n"
read CHOICE

if [ "$CHOICE" = "y" ]
then
echo
ls -1
echo
fi

echo "Enter pattern to be removed from filenames: "
IFS=
read SPATT
echo -n "Removing pattern \"$SPATT\"... "
SPATT=`echo "$SPATT" | sed -e

Читать полностью…

r_bash

Something i do on all BASH scripts I write. What do you guys think?
https://redd.it/1hz2kku
@r_bash

Читать полностью…

r_bash

Reading when user enters a response without hitting enter

I have this:

cat <<EOF
Press x
EOF

read response

if [ $response == 'x' ]; then
printf "you did it!"

else
printf "dummy"
fi

This requires the user to press x [Enter], though.

How do I get it to listen and respond immediately after they press x?

https://redd.it/1hyqv8v
@r_bash

Читать полностью…

r_bash

How to Display Dynamic Menu Under Active Command Line Input in Bash Terminal?

I want to write a Bash script that implements a menu which updates in real-time directly beneath the active command line as the user types. Like what you see here with ble.sh , where the user was able to select "tmux" from options displayed below the line they were typing on.

I'm still a beginner, so I wanted to know if this is something feasible for me right now, or if it's more complicated than it appears. If it is feasible, how can I get started?

https://redd.it/1hxz61b
@r_bash

Читать полностью…

r_bash

arguments with spaces to a script, run from another script

So here is an example with a simple script that just prints out its first, second and third argument.

Works as intended with both single and space-embedded arguments

~/tmp$ cat args.sh
#!/usr/bin/env bash                                                                 
echo "1: $1"
echo "2: $2"
echo "3: $3"

~/tmp$ ./args.sh a b c
1: a
2: b
3: c

~/tmp$ ./args.sh a 'b b' c
1: a
2: b b
3: c

But now if i run this script from another script that uses a variable to pass the arguments, then the quotations dont work.

How can i get this working so that "b b" is understood as one single argument?
In reality these arguments are fetched from a text-file, but I tried to simplify as much as possible here.

~/tmp$ cat wrapper.sh 
#!/usr/bin/env bash
args="a 'b b' c"
./args.sh $args

~/tmp$ ./wrapper.sh 
1: a
2: 'b
3: b'

https://redd.it/1hxzsgy
@r_bash

Читать полностью…

r_bash

how delete 3 pages from pdf using qpdf?

hi, I am trying to delete 3 pages from a pdf, I can not do that.

I tryied with:

qpdf original.pdf --empty --pages . 1-100,r90,r95,r100 -- out.pdf

even I tryed with x90,95,100 but do a mistake

Thank you and regards!

https://redd.it/1hxs112
@r_bash

Читать полностью…

r_bash

Email from Bash script loses its formatting

I'd appreciate help in fixing the following Bash script so it will retain the spacing and formatting as seen when running it as a simple Bash script.

When its content is embedded into an email it loses all that formatting.

TIA!

#!/usr/bin/bash

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DATADIR=/mnt/data
HOSTNAME=$(hostname)
EMAILRECIP="admin@example.com"

/usr/sbin/sendmail -it << EOF
From: Server <adm@$HOSTNAME>
To: $EMAILRECIP
Subject: Quota report from $HOSTNAME
Content-Type: text/plain; charset=UTF-8

$(date)
$(echo " Path Hard-limit Soft-limit Used Available Soft-limit exceeded? Hard-limit exceeded?")
$(echo "-------------------------------------------------------------------------------------------------------------------------------")
$(ls -1 $DATADIR | while read -r DIR; do
gluster volume quota data list /"$DIR" | tail -n +3 | cut -c2-
done)
$(echo "----------------------------------------------------------------")
EOF

https://redd.it/1hxi62b
@r_bash

Читать полностью…

r_bash

Using font colors in a HEREDOC

u/geirha made a comment in another thread about the proper way to use printf, and that sent me down a rabbit hole of learning the different printing styles. I don't do a lot of printing to the screen in bash (usually just error messages), but my 13 year old dog passed away recently so I'm distracting myself with unimportant projects.

As far as I can tell, the only way to use a HEREDOC is with cat. Which is fine, but when I try to change the font color it prints the literal text instead of changing the font:

cat << EOF
\0330;31m Whatever, dude \033[0m
EOF

# \033[0;31m Whatever, dude \033[0m

The only option I've found to change font colors is to create variables using either `echo -e` or `tput`:

# using tput
RED=$(tput setaf 1)
NORM=$(tput sgr0)

# or, using echo -e
RED=`echo -e "\033[0;31m"`
NORM=`echo -e "\033[0m"`

cat << EOF
${RED}Whatever, dude${NORM}
EOF

Are those really the only / best ways to do this?

[
https://redd.it/1hvy9u7
@r_bash

Читать полностью…

r_bash

Passing global variables into other scripts

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 scripts, 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 scripts i talk about could be written by user "to allow customization"
So to make it easier on user to write his script, 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 script into vars.sh
But i want to make the function generic and work in any script, 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

Читать полностью…

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

Читать полностью…

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

Читать полностью…

r_bash

The EveryDay Concerned Citizen | A site to get info, take action, make change happen
https://everydayconcerned.net/

https://redd.it/1hsznsb
@r_bash

Читать полностью…

r_bash

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

Читать полностью…

r_bash

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 scripts 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 script 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

Читать полностью…

r_bash

's/\[/\\\[/g' -e 's/\]/\\\]/g' -e 's/ /\\\ /g' -e 's/\./\\\./g' -e 's/{/\\\{/g' -e 's/}/\\\}/g' -e 's/\!/\\\!/g' -e 's/\&/\\\&/g' `
#Escape out all special characters so it works in sed
for i in *
do
FNAME=`echo "$i" | sed s/"$SPATT"//`
if [ "$i" != "$FNAME" ]
then
mv "$i" "$FNAME"
fi
done

echo "done"
fi

#------------------Trim directory names after year

if echo "$OPT" | grep -q 't'
then
echo -n "Trimming directory names after title and year... "
for h in *
do

if [ -d "$h" ]
then
FNAME=`echo "$h" | sed 's/\[\ www\.Torrenting\.com\ \]\ \-\ //' | sed 's/1080//' | sed 's/1400//'`
EARLY="$FNAME"
FNAME=`echo "$FNAME" | sed 's/\(^.*([0-9]\{4\})\).*$/\1/'` #this won't do anything unless the year is in parentheses

if [ "$FNAME" = "$EARLY" ] #testing whether parentheses-dependent sed command did anything
then
FNAME=`echo "$FNAME" | sed 's/\(^.*[0-9]\{4\}\).*$/\1/'` #if not, trim after last digit in year
FNAME=`echo "$FNAME" | sed 's/\([0-9]\{4\}\)/(\1)/'` #and then add parentheses around year
mv "$h" "$FNAME" #and rename
else
mv "$h" "$FNAME" #if the parentheses-dependent sed worked, just rename it
fi

fi

done
rename 's/\[\(/\(/' *
rename 's/\(\(/\(/' *
echo "done"
fi

#------------------Match file names to parent directory names

if echo "$OPT" | grep -q 'm'
then
echo -n "Matching filenames to parent directory names and deleting junk files... "

for h in *
do

if [ -d "$h" ]
then
rename 's/ /_/g' "$h"#replace spaces in directory names
fi#with underscores so mv doesn't choke

done

for i in *
do

if [ -d "$i" ]
then
cd "$i"

for j in *
do
#replace spaces with underscores in all filenames in each subdirectory
rename 's/ /_/g' *
done

cd ..
fi

done

for k in *
do

if [ -d "$k" ]
then
cd "$k"#go into each directory
find ./ -regex ".*[sS]ample.*" -delete#take out the trash
NEWN="$k"#NEWN="directory name"

for m in *
do
EXTE=`echo $m | sed 's/^.*\(....$\)/\1/'`#read file extension into EXTE
if [ "$EXTE" = ".mp4" -o "$EXTE" = ".m4v" -o "$EXTE" = ".mkv" -o "$EXTE" = ".avi" ]
then
mv -n $m "./$NEWN$EXTE"

elif [ "$EXTE" = ".srt" ]
then
#check to see if .srt file is actually real
FISI=`du "$m" | sed 's/\([0-9]*\)\t.*/\1/'`
#is it real subtitles or just a few words based on file size?
if [ "$FISI" -gt 10 ]
then
mv -n $m "./$NEWN.eng$EXTE"#if it's legit, rename it
else
#if it's not, delete it
rm $m
fi

elif [ "$EXTE" = ".sub" -o "$EXTE" = ".idx" ]
then
mv -n $m "./$NEWN.eng$EXTE"

elif [ "$EXTE" = ".nfo" -o "$EXTE" = ".NFO" -o "$EXTE" = ".sfv" -o "$EXTE" = ".exe" -o "$EXTE" = ".txt" -o "$EXTE" = ".jpg" -o "$EXTE" = ".JPG" -o "$EXTE" = ".png" -o "$EXTE" = "part" ]
then
rm $m#delete all extra junk files
fi

done

cd ..
fi
done

#turn all the underscores back into spaces
#in directory names first...
rename 's/_/ /g' *

for n in *
do
if [ -d "$n" ]
then
cd "$n"
for p in *
do
rename 's/_/ /g' *#...and files within directories
done
cd ..
fi
done

fi

#---------------------List directories and files

echo

Читать полностью…

r_bash

A script for renaming movie files

Most of the time, when you get a movie file it's a directory containing the video file, maybe some subtitles, and a bunch of other junk files. The names of the files are usually crowded and unreadable. I used to rename them all myself, but I got tired of it, so I learned how to write shell scripts.

stripper.sh is really useful tool, and it has saved me a huge amount of work over the last few years. It is designed to operate on a directory containing one or many subdirectories, each one containing a different movie. It formats the names of the subdirectories and the files in them and deletes extra junk files. This script is dependent on "rename," which is really worth getting, it's another huge time saver.

It has four options which can be used individually or together:

1. Option p: Convert periods and underscores to spaces
2. Option t: Trim directory names after title and year
3. Option s: Search and remove a pattern/string from directory and file names
4. Option m: Match file names to the names of their parent directories
5. No option or any other letter entered: Shows the user guide.

Here is an example working directory before running stripper.sh:

Cold.Blue.Steel.1988.1080p.s3cr3t.0ri0le.6xVHAYT
↳Cold.Blue.Steel.1988.1080p.s3cr3t.0ri0le.6xVHAYT.mkv
poster.JPG
english.srt
info.nfo
other torrents.txt

Angel Feather 1996 720pan0rtymous2200
↳Angel Feather 1996 720pan0rtymous2200.mp4
english SDH.srt
screenshot128620.png
screenshot186855.png
screenshot209723.png
readme.txt
susfile.exe

...and after running stripper.sh \-ptm:

Cold Blue Steel (1988)
↳Cold Blue Steel (1988).mkv
Cold Blue Steel (1988).eng.srt

Angel Feather (1996)
↳Angel Feather (1996).mp4
Angel Feather (1996).eng.srt

It's not perfect, there are some limitations, mainly if there are sub-subdirectories. Sometimes there are, with subtitle files or screenshots. The script does not handle those, but it does not delete them either.

Here is the code: (I'm sorry if the indents are screwed up, reddit removed them from one of the sections, don't ask me why)

#!/bin/bash

OPT=$1

#----------------Show user guide

if -z "$OPT" || `echo "$OPT" | grep -Ev [ptsm ]
then
echo -e "\033[38;5;138m\033[1mUSAGE: \033[0m"
echo -e "\t\033[38;5;138m\033[1mstripper.sh\033[0m [\033[4mOPTIONS\033[0m]\n"
echo -e "\033[38;5;138m\033[1mOPTIONS\033[0m"
echo -e "\tPick one or more, no spaces between. Operations take place in the order below."
echo -e "\n\t\033[38;5;138m\033[1mp\033[0m\tConvert periods and underscores to spaces in file and directory names."
echo -e "\n\t\033[38;5;138m\033[1ms\033[0m\tSearch and remove pattern from file and directory names."
echo -e "\n\t\033[38;5;138m\033[1mt\033[0m\tTrim directory names after title and year."
echo -e "\n\t\033[38;5;138m\033[1mm\033[0m\tMatch filenames to parent directory names.\n"

exit 0
fi

#-----------------Make periods and underscores into spaces

if echo "$OPT" | grep -q 'p'
then
echo -n "Converting underscores and periods to spaces... "

for j in *
do

if [ -d "$j" ]
then
rename -E 's/\_/\ /g' -E 's/\./\ /g' "$j"
elif [ -f "$j" ]
then
rename -E 's/\_/\ /g' -E 's/\./\ /g' -E 's/ (...)$/.$1/' "$j"
fi

done

echo "done"
fi

#---------------Search and destroy

if echo "$OPT" | grep -q 's'
then
echo "Remove search pattern from filenames:"
echo "Show file/directory list? y/n"
read CHOICE

if [ "$CHOICE" = "y" ]
then
echo
ls -1
echo
fi

echo "Enter pattern to be removed from filenames: "
IFS=
read SPATT
echo -n "Removing pattern \"$SPATT\"... "
SPATT=
echo "$SPATT" | sed -e

Читать полностью…

r_bash

I would really appreciate checking out my bash project which i spent some time creating after leaning Bash. Its really an amazing language and I would really appreciate any tips and hacks which I can use to make my scripts more effective.
https://github.com/irfanbroo/Air_QualityWeatherAPI_bash

https://redd.it/1hyzma2
@r_bash

Читать полностью…

r_bash

Does rbash disable functions?

I've built a sandbox that restricts the user to the rbash shell. But what I've found was that the user was still able to execute functions which can be bad for the environment because it enables the use of a fork bomb:

:(){ :|:& };:

#

I don't want to set a process limit for the user. I would like to just disable the user from declaring and executing functions.

https://redd.it/1hy2mnw
@r_bash

Читать полностью…

r_bash

Bash unpredictability

Does anyone know why Bash works the way it does? Why are there so many ways to do a particular thing, with most only yielding partially successful results and, say, one out of seven giving the result you're looking for?

https://redd.it/1hy0qvf
@r_bash

Читать полностью…

r_bash

Happy Birthday Bash!
https://redd.it/1hxzh3d
@r_bash

Читать полностью…

r_bash

Show: writenow: the command-line clone of Ensō

writenow is a opensource command-line clone of Ensō I first saw Ensō two years ago in HN and was very interested in the idea. I wanted an opensource version of it installed on my machine. So, I tried to clone it using bash script as a command-line version, you can find here.

The project hasn't been maintained for few months as I got busy on my 9to5 job. However, I’ve dedicated time for open-source contributions starting in 2025, and one of my current goals is to further develop writenow.

My next steps are to create a to-do list of future tasks and work on them in short-term iterations.

All issues, PRs, and feedback are welcome, and I’d be delighted if you starred the repository on GitHub.

demo of writenow



https://redd.it/1hxd041
@r_bash

Читать полностью…

r_bash

I built list of all (known) terminals - The Terminal Directory
https://termui.sh

https://redd.it/1huxq8b
@r_bash

Читать полностью…

r_bash

in the bash mountains ;-)
https://redd.it/1hvzjcw
@r_bash

Читать полностью…

r_bash

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 script. 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 script, it all fails.

For example, I'm passing it to the script as follows:

./script.sh --eco "\"E6-90-9\"" --input testdbs/testdb.pgn

And the script 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 script, 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

Читать полностью…

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

Читать полностью…

r_bash

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&amp;format=png&amp;auto=webp&amp;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

Читать полностью…

r_bash

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 Description 1
234234234 #Mod Description 2
345345345 #Mod Description 3
"

Basically, list each modID in a new line + adding a #comment?


Best regards, <3

https://redd.it/1hswaqd
@r_bash

Читать полностью…

r_bash

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 scripting language and/or the nature of a shell scripting 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

Читать полностью…

r_bash

Pipe to background process

Hi!

I am trying to write a script 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 descriptor without a file, or some other way to approach the problem perhaps?

I am trying to execute this script on Mac, so no procfs.

https://redd.it/1hsc6fw
@r_bash

Читать полностью…
Subscribe to a channel