r_bash – Telegram
Does anyone else get by using ctrl + r 90% of the time?

Honestly, this bash command is the great majority of what I do to as a senior full stack developer using bash. Can anyone else relate?

https://redd.it/11xw5zb
@r_bash
Help with Email Suppression Script from Command Line (Unix / Linux / macOS)

#!/bin/bash(sed 's/^/A /' $1;sed 's/^/B /' $2)|sort -fk 2|uniq -ius 2|sed -ne '/^B /d' -e 's/^A //p'

Enter the following in the macOS Terminal App:

./suppress.sh FileA FileB > FileC

​

A friend created this custom noscript for me circa 2010 to solve a problem I had with email marketing. If I had List A that needed to be sent to, but I also had List B of people who should not receive the email, the noscript would create List C, which was made by taking List A and then subtracting the contents of List B. (List C = List A - List B). It was designed to work specifically with email addresses, but I suppose it would work fine for single words on a line.

​

It used to work fine, but I haven't used it in a while and there appears to have been enough changes in macOS that it needs a bit of love. Can anyone help with the required updates to make it work? Please see example below.

​

EXAMPLE


LIST A (original list)
\---------------------------------------------
one@gmail.com
two@gmail.com
three@gmail.com
four@gmail.com
five@gmail.com
six@gmail.com
seven@gmail.com
eight@gmail.com
nine@gmail.com
ten@gmail.com
LIST B (list of emails to suppress)
\---------------------------------------------
one@gmail.com
three@gmail.com
five@gmail.com
seven@gmail.com
nine@gmail.com
when run, it would create List C which would look like below


LIST C (new list of A-B)
\---------------------------------------------
two@gmail.com
four@gmail.com
six@gmail.com
eight@gmail.com
ten@gmail.com

https://redd.it/11xvb91
@r_bash
please help!

I have a noscript that just sets up Fedora server and a WM but that is not relevant.

the problem is that the fonts do not download to home or unzip to .fonts/truetype. Here is the code snippet

while true; doread -p "Would you like to install JetBrainsMono nerd font Y/N " fontinstcase $fontinst iny|Y ) echo "# Adding Nerd fonts to "$HOME"/.fonts/truetype #"; mkdir"$HOME"/.fonts/truetype; wget-q `https://github.com/ryanoasis/nerd-`fonts/releases/download/v2.3.3/JetBrainsMono.zip;unzip "$HOME"/JetBrainsMono.zip -d "$HOME"/.fonts/truetype;;

n|N ) echo "Aborted, skipping..."

esac

done

Please ignore the formatting it did not get copied over correctly.

https://redd.it/11y3tzr
@r_bash
Need help idk what to try anymore I don’t know how to code really

i have no idea how to code but i need help

i run a Minecraft server for me and some friends and i wanted to add an automatic restart i have worked with chat gtp to try and add this but it wont work here are some we tried. this is in windows 11 CMD. i have more version i have tried but i didn't save them. plz help

START CODE THAT WORKS/original code

echo off



call settings.bat



:start_server

echo Starting SevTech Ages Server...

java -server -Xms1024M -Xmx25600M %JAVA_PARAMETERS% -jar %SERVER_JAR% nogui

pause

exit /B



goto start_server

\---------------------------------------------------------------------------------------

here's some I have tried

\---------------------------------------------------------------------------------------

echo off



call settings.bat



:start_server

echo Starting SevTech Ages Server...

java -server -Xms1024M -Xmx25600M %JAVA_PARAMETERS% -jar %SERVER_JAR% nogui

pause

exit /B



REM Timer to announce server restart

set /a counter=0

:timer_loop

set /a counter+=1

if %counter% equ 28800 (

echo SERVER RESTARTING IN 10 MINS

echo [1m [33mSERVER RESTARTING IN 10 MINS [0m

timeout /t 600

call :restart_server

) else (

timeout /t 60

goto timer_loop

)



REM Function to stop and restart server

:restart_server

echo Stopping SevTech Ages Server...

taskkill /f /im java.exe

echo SevTech Ages Server has been stopped.

echo Restarting SevTech Ages Server...

java -server -Xms1024M -Xmx25600M %JAVA_PARAMETERS% -jar %SERVER_JAR% nogui

echo SevTech Ages Server has been restarted.

goto start_server

\------------------------------------------------------------------------------------------------------------------

echo off



call settings.bat



:start_server

echo Starting SevTech Ages Server...

java -server -Xms1024M -Xmx25600M %JAVA_PARAMETERS% -jar %SERVER_JAR% nogui

pause

exit /B



REM Add timer for server restart

set "colors=1 3 4 6 2 5"

set "color_index=0"

for /l %%x in (1,1,28800) do (

if %%x==1 (

echo \^[[1;32;47mServer started. Starting timer...\^[[0m

)

if %%x==28800 (

for %%c in (%colors%) do (

set /a "color_index=(color_index+1)%%6"

echo \^[[1;%color_index%;47mSERVER RESTARTING IN 10 MINS\^[[0m

timeout /t 10 /nobreak > nul

)

echo \^[[1;31;47mSERVER RESTARTING NOW\^[[0m

taskkill /f /im java.exe > nul

java -server -Xms1024M -Xmx25600M %JAVA_PARAMETERS% -jar %SERVER_JAR% nogui

)

)

https://redd.it/11ye68j
@r_bash
Why change directory in a noscript suite?

I am not the strongest programmer (since I am a phycisist), but have been tasked with migrating a series of old noscript suites to a different environment.

In several of these noscripts, I will see commands such as:

"cd $BINDIR"

"cd ../data"

"cd $PWD"

To me, this is a mess, and begs for errors and issues in case of developments that won't work because you're suddenly in a different directory than the project root. Does anyone know if there is a reason for changing directory in a noscript suite? Why not run everything from the project home? Maybe I am missing some smarter idea behind the structure here?

https://redd.it/11ykqgm
@r_bash
How to create a 'Dummy File' in Bash

Using a command called "Fallocate", you can easially create a small or even very large file that does nothing but take up space.

Command:

fallocate -l <size><binary_prefix> <filename>

Examples:

1 MB FILE:

fallocate -l 1m MyTXT.txt

1 GB FILE:

fallocate -l 1g MyPDF.pdf

1 TB FILE:

fallocate -l 1t MyFile

https://redd.it/11yvm45
@r_bash
Trying to make a noscript with the arithmetic operation on the two numbers

How could you do a method that you can take an input such as

(Number1)+, -, *, /, %(Number2)

So if person types 7+1

Returns 8, but also can check for the other operators such as -,*,/,%?

Instead of just checking for one operator

https://redd.it/11z0lxt
@r_bash
Asking for help with elifs and functions

I was attempting to do an assignment for my class, but I'm sure I went wrong somewhere when I was trying to do the code. I'm not the most experienced in bash, so I tried my best. I'm just asking where exactly I went wrong while doing this.

For context purposes ONLY, the assignment was:

Write a program that asks the user to enter five test scores in bash shell noscript, please.The program should display a letter grade for each score and the average test score. Design the following functions in the program:
● calcAverage—This function should accept five test scores as arguments and
return the average of the scores.
● determineGrade—This function should accept a test score as an argument
and return a letter grade for the score (as a String), based on the following
grading scale:
Score Letter Grade
90–100 A
80–89 B
70–79 C
60–69 D
Below 60 F

&#x200B;

I do not intend on looking for answers! I'm simply wondering where I went wrong.

https://preview.redd.it/7ndblqi5xepa1.png?width=464&format=png&auto=webp&v=enabled&s=2f75b3a627fde4edcbc7da8ad5f3661a54d342a8

https://redd.it/11z85eg
@r_bash
Trick condition using cron

Let's say I have a cron job that checks certain system condition. For purposes to describe this scenario, my cron job checks the RAM utilization every 5 min and if the condition is met, the cron kills a process and creates a file. The process restarts automatically BUT the cron should check continuously but should not kill the process AGAIN in the next 6 hours. Any ideas how to address such scenario ?

https://redd.it/11zi6w7
@r_bash
How to make it case-insensitive

I have a noscript like this:

#!/bin/bash

VIDEO_EXT=".mkv"

AUDIO_EXT=".mka"

SUBTITLES_EXT=".ass"



REMOVE_OLD_FILES=true



for filename in ./*${VIDEO_EXT}; do

file_name="$(basename "$filename" "$VIDEO_EXT")"

merged_file_name="${file_name}-merged${VIDEO_EXT}"



stream_count=1



audio_inputs=""

audio_map=""



# Detect all audio

for audio_folder in ./Sounds/*; do

if [ -d "$audio_folder" ]; then

audio_inputs="${audio_inputs} -i \"${audio_folder}/${file_name}${AUDIO_EXT}\""

audio_map="${audio_map} -map ${stream_count} -metadata:s:a:${stream_count} noscript=\"${audio_folder##*/}\""

stream_count=$(expr $stream_count + 1)

fi

done



subnoscripts_inputs=""

subnoscripts_map=""



# Detect all subnoscripts

for subnoscripts_folder in ./Subnoscripts/*; do

if [ -d "$subnoscripts_folder" ]; then

subnoscripts_inputs="${subnoscripts_inputs} -i \"${subnoscripts_folder}/${file_name}${SUBTITLES_EXT}\""

subnoscripts_map="${subnoscripts_map} -map ${stream_count}"

stream_count=$(expr $stream_count + 1)

fi

done



# Converting

eval "ffmpeg -y -i \"${filename}\" ${audio_inputs} ${subnoscripts_inputs} -map 0:v -map 0:a ${audio_map} ${subnoscripts_map} -c:v copy -c:a copy -c:s srt -shortest \"${merged_file_name}\""



# Removing

if [ "$REMOVE_OLD_FILES" = true ]; then

# Removing original videofile

eval "rm \"${filename}\""



# Removing audiofiles

for audio_folder in ./Sounds/*; do

if [ -d "$audio_folder" ]; then

eval "rm \"${audio_folder}/${file_name}${AUDIO_EXT}\""

fi

done



# Removing subnoscripts

for subnoscripts_folder in ./Subnoscripts/*; do

if [ -d "$subnoscripts_folder" ]; then

eval "rm \"${subnoscripts_folder}/${file_name}${SUBTITLES_EXT}\""

fi

done



# Renaming merged videofile to original name

eval "mv \"${merged_file_name}\" \"${filename}\""

fi

done

&#x200B;

&#x200B;

I would like it to be case insensitive. because I compress some shows and then add soundtracks and subnoscripts.

Sorry if there was, I just do not know noscripts and programming

https://redd.it/11zj7mm
@r_bash
When I make a variable, does the code in that variable run itself?

Hello, I've just started learning Bash at home. But I'm not sure if when I "declare" a variable, if the code runs itself. Because I'm using freecodecamp to learn Bash, and I'm learning to use Bash and putting text from csv files into SQL.

I have this line of code

INSERTMAJORRESULT=$($PSQL "INSERT INTO majors(major) VALUES('$MAJOR')")

$PSQL just logs in and out of PSQL.

But what I'm not understanding is that I do not echo the $INSERT_MAJOR_RESUT, it's just there. Yet it still runs the code. I thought I would need to echo that variable for it to run that code.

&#x200B;

Here is all of it. And the code under # insert major comment runs every loop and puts data into the database. I'm confused

# Script to insert data from courses.csv and students.csv into students database

PSQL="psql -X --username=freecodecamp --dbname=students --no-align --tuples-only -c"
cat coursestest.csv | while IFS="," read MAJOR COURSE
do
if [[
$MAJOR != "major" ]]
then
# get major
id
MAJORID=$($PSQL "SELECT majorid FROM majors WHERE major='$MAJOR'")
# if not found
if [ -z $MAJOR_ID ]
then
# insert major
INSERTMAJORRESULT=$($PSQL "INSERT INTO majors(major) VALUES('$MAJOR')")
fi
fi
done

https://redd.it/11zl43y
@r_bash
(y/n) in printf not allowed? commenting it prints to another file`?

I want to create a nice "loop creator" noscript, helping me with creating bash loops easily.

All works fine, but in the end I have this command to print the loop out, and it doesnt work.

```
printf """#!/bin/bash

while true; do
read -p "$question (y/n) > " yn
case $yn in
[Yy]* ) $ifyes && break;;
[Nn]* ) $ifno && break;;
* ) echo "Please answer yes or no.";;
esac
done""" >> $path/$loopname
```

When I leave it like that, it gives an error that the brackets are not allowed. But I use them exactly like that in other parts? I guess its related to the $question .

If I comment the brackets with

```
printf """#!/bin/bash

while true; do
read -p "$question \(y\/n\) > " yn
case $yn in
[Yy]* ) $ifyes && break;;
[Nn]* ) $ifno && break;;
* ) echo "Please answer yes or no.";;
esac
done""" >> $path/$loopname
```

It does really weird stuff, breaking the printf command and printing the rest as the filename of a new file.

https://redd.it/11zmb41
@r_bash
Unique list of numbers, in order of appearance

Small tool, cool to have when you need it, the tools supplied works most often with sorted lists, that is, in order to make things unique, and thereby distorts the chronological order.

#!/bin/bash
mapfile numbers
count=${#numbers@}
declare -A uniqlist=()

for ((i=1;i<count;i++)) ; do
this
elm=${numbers$i}
if [ ! -v uniq_list[$this_elm ]] ; then
echo $thiselm
uniq
list$this_elm=1
fi
done

https://redd.it/11znrn7
@r_bash
Have you made a bash noscript that improved your life on some way? My examples

Hi all,

I am experimenting with bash noscripts lately. I am no programmer, but the fact that I can automate some things to improve my life in some way is very enjoyable, despite being a complete noob in the matter.

I do not write about noscripts that sysadmins would probably use. I write about simple, everyday stuff. I asked myself "what can I automate in my life through noscripts?"

Here are my examples:

1. Automatic sorting of photos and videos of my newborn daughter. I have A TON of them (like thousands), and sorting them by creating folders, then cutting and pasting would be a chore. So I made a simple noscript that creates a folder with a name of the year, inside them create folders named by months, and then scans through all the files. Based on their date the noscript moves the file to appropriate year/month.

Very handy, very fast. My wife was amazed :)

2. Expense report - a noscript that reads a CSV file of my expense statement for a chosen month, and then it sums up all my expenses by categories, based on keywords. If a keyword exists in a denoscription, it links the expense to the category automatically.

As a result I reduced the time of making this report every month from at least 2hrs to 5 minutes (most of them is downloading a CSV file from a bank account).

I am eager to make another noscripts that would automate some things for me.

What are your examples od noscripts, that improved your everyday life in a similar way?

EDIT: I know that there is a typo in the noscript, but it seems that I can't change it. Oh, well...

https://redd.it/11zwt18
@r_bash
while loop until keypress

Hi all...

I am wanting to loop a noscript until a keypress, at which point I want the noscript to exit, or run a different function within the noscript and return to the while loop.

How would I proceed to do this?

https://redd.it/120cl8i
@r_bash
Double dashes for options are replaced by "–" by pandoc, how to fix it?

Here is my makefile and there is my man page.

After conversion I obtain this:

SYNOPSIS
md-to-clip –help|-h
md-to-clip –version|-v
md-to-clip –author|-a
md-to-clip –email|-e

instead of double-dashes:

SYNOPSIS
md-to-clip --help|-h
md-to-clip --version|-v
md-to-clip --author|-a
md-to-clip --email|-e

How to fix it? I suppose it's the reason why VS Code Bash IDE extension can't parse my man page and suggest available flags for md-to-clip noscript.

https://redd.it/120k1ck
@r_bash
Why my snippet code is not working?

So I'm trying to mess with bash making a really compressed code that shows you your network connection status and I came up with this:

#!/bin/bash

wifistate=$(cat /sys/class/net/wlp3s0/operstate)
ethernet
state=$(cat /sys/class/net/enp0s25/operstate)

if $wifi_state -eq "up" && STAT="up" || if $ethernet_state -eq "up" && STAT="up" || STAT="down"

echo "$STAT"

When compiling it I get the error line 9: syntax error: unexpected end of file . Can someone please enlighten me and tell me what is wrong with it?

https://redd.it/121pypq
@r_bash
Automatic Distro Downloader

I need help writing a bash shell noscript that can download some linux distros for me and also check for newer versions. I spend many hours every six months having to go to the websites to update to the newest version as I utilize many different versions of linux and switch commonly. I store these on local harddrives and it becomes time consuming downloading and etc. These distro's are : Kali Linux 64 and 32 bit bare metal & the 64 bit everything version, Arch Linux, CSI Linux, Debian Linux, Fedora, Linux Mint, Manjaro (Xfxe and KDE versions, Parrot Linux, Puppy Linux, Slackware Linux, Tails, Tiny Core, Trace Labs VM, Ubuntu, Whonix, GUIX, PUREOS, and Trisquel. Thanks.

https://redd.it/121tb2j
@r_bash