r_bash – Telegram
Instructions on how to grab multiple downloads using loop

I am downloading many hundreds of military documents on their use of aerosol atmospheric injection for weather control and operational strategies. One example is here:

https://babel.hathitrust.org/cgi/imgsrv/image?id=uc1.d0008795742&attachment=1&tracker=D4&format=image%2Fjpeg&size=ppi%3A300&seq=1

This is just a scanned book which is unclassified. I already have a PDF version of the book taken directly from gpo.gov and govinfo.gov but I want to save this scanned original. This link connects to a JPG scan, and the seq variable is the page number.

I want to use wget or curl or any other useful tool to pass a loop of the URL and grab all of the pages at one time.

Here is the conceptual idea:

FOR %COUNT in (1,1,52) do (
WGET "https://babel.hathitrust.org/cgi/imgsrv/image?id=uc1.d0008795742&attachment=1&tracker=D4&format=image%2Fjpeg&size=ppi%3A300&seq=%COUNT"
)

If you can help with this, it would be much appreciated. Thank you

Linux Mint 21.1 Cinnamon
Bash 5.1.16

https://redd.it/1itm3ss
@r_bash
can someone explain /bin/bash -c

The following 2 commands yield nothing or limited subset

sudo -u testuser echo $PATH <---I realize there is an option in visudo to preserve
sudo -u testuser env < --- this gives a much smaller/truncated output

Whereas the commands below give a the same output as if I'm logged in as the testuser

sudo -i -u testuser /bin/bash -c 'echo $PATH' <---this gets passed through regardless of option in visudo
sudo -i -u testuer /bin/bash -c 'env'


I have a guess as to what is going on but I am not 100% sure



https://redd.it/1itsp9k
@r_bash
Remove whitespaces from text but only IN words. Is it even possible ?

Hello,


I have a larger textfile in german, that looks like this:


Hello this is an i n t e r e s t i n g text but i dont l i k e whitespaces.


In some random words there is also a whitespace between every character. My only idea is to create an large txt file with all german words in t h i s way and replace them if they happen. Does someone know a more elegant way ?

https://redd.it/1iu6xr4
@r_bash
How to remove Enter key symbol?

When executing cat /sys/firmware/devicetree/base/model on my Raspberry Pi in order to get the model of Pi I am working with, the output looks as follows:

> cat /sys/firmware/devicetree/base/model
Raspberry Pi 3 Model B Rev 1.2⏎


How can I remove that "Enter key symbol" at the end?

https://redd.it/1iuoq5q
@r_bash
Can I Use the Same Ubuntu Installation for Both WSL2 and a Bootable OS on My External SSD?

I’m setting up Ubuntu on my external SSD and I want to achieve a specific workflow:

1. Boot Ubuntu directly from my SSD when I need a full Linux environment.
2. Use the same Ubuntu installation inside Windows as WSL2 (instead of having two separate installations).
3. Keep all my files, user settings, and configurations the same between WSL2 and the bootable OS.

I tried looking into WSL2 VHDX files, but they seem to work as a virtual disk rather than a direct partition mount. Ideally, I’d like to install Ubuntu as a normal OS on my SSD, and then make Windows mount the same filesystem inside WSL2.

Has anyone done this before? Any issues with permissions, GRUB, or performance? Would love to hear your suggestions!

# System Details:

External SSD: 1TB
Planned Ubuntu Partition: 100-150GB (EXT4)
Windows Version: Windows 11
WSL Version: WSL2

Let me know if this setup is possible or if there’s a better way! 🚀

Thanks!

https://redd.it/1iuqqnq
@r_bash
Efficient Execution

Is there a way to load any executable once, then use the pre-loaded binary multiple times to save time and boost efficiency in Linux?

Is there a way to do the same thing, but parallelized?

My use-case is to batch run the exact same thing, same options even, on hundreds to thousands of inputs of varying size and content- and it should be quick. Quick as possible.

https://redd.it/1iurn0j
@r_bash
Name associative array after variable

I need to be able to do something like "Declare -A $var", $var"${key}"="${value}", and echo "$var${key}". What would the correct syntax for this be?

https://redd.it/1ivlhfg
@r_bash
What is wrong with my command using rsync?

Hi
using rsync from home to media (a pendrive) I get an error 30

rsync: receiver mkstemp "/media/jazei/MSDB/Vim/.plugins.txt.uul3Lm" failed: Read-only file system (30)

even using dirdiff I get same error read only file system...

what should I check?

I tryed chmod 777and sudo chmod... but nothing I am shielded !

this is a micro sd memory ...

see this URL screen shot: https://imgbox.com/9olj7ivT

Thank you and regards!

https://redd.it/1ixzbe1
@r_bash
I configured my bash to simulate bottom padding so my command prompt is never on the last row
https://redd.it/1iya9vk
@r_bash
Where to put sourced functions?

What is the recommended place to put sourced functions in Bash? What if I want to share those functions with other users?


`.bashrc` is probably the most obvious place, but that doesn't seem to scale very well. Is there maybe some standardized place where I can put them?

https://redd.it/1iypvm8
@r_bash
pgrep shows PID but there's no instance

I'm confused why `pgrep tmux` shows the PID in the noscript even though tmux hasn't been called yet (and I confirmed `pgrep tmux` shows nothing prior to running the noscript):

Script:

#!/usr/bin/bash

if [[ $# -eq 1 ]]; then
selected=$1
else
selected=$(find ~/bin/ ~/work/builds ~/projects -mindepth 1 -maxdepth 1 -type d | fzf)
fi

if [[ -z $selected ]]; then
exit 0
fi

selected_name=$(basename "$selected" | tr . _)
tmux_running=$(pgrep tmux)

echo TMUX=$TMUX
echo tmux_running=$tmux_running
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
tmux new-session -s $selected_name -c $selected
exit 0
fi

if ! tmux has-session -t=$selected_name 2>/dev/null; then
tmux new-session -ds $selected_name -c $selected
fi
tmux switch-client -t $selected_name

My shell:

# same condition as in noscript
$ ~ $ [[ -z $TMUX ]] && [[ -z $tmux_running ]] && echo ok
ok
$ ~ $ tmux kill-server
no server running on /tmp/tmux-1000/default
$ ~ $ pgrep tmux
$ ~ $ tmux-sessionizer
find: ‘/home/enory/work/builds’: No such file or directory
find: ‘/home/enory/projects’: No such file or directory

TMUX=
tmux_running=38971
no current client

Here, there's a PID of `38971` for tmux even though tmux hasn't started yet. As a result, the last command of the noscript runs, resulting in `no current client`.

How is this possible? **What's bizarre is if I run `bash -x tmux-sessionizer`, then the results are expected, i.e. there's no PID yet and the noscript works as intended.**

https://redd.it/1izaz8d
@r_bash
Best way to learn BASH noscripting as a lawyer?

I don’t come from a tech or computer science background—I’m an attorney, and a significant portion of my work revolves around legal documentation. Much of my daily tasks involve repetitive processes, such as OCR (Optical Character Recognition) for scanned documents, formatting files, and managing large volumes of paperwork.

A few days back, I had a monotonous task in front of me: OCRing about 40 PDFs. Under normal circumstances, this would involve opening each document separately or using an online service, which is time-consuming and inefficient. The sheer drudgery of the task led me to wonder if there was an easier way.

That's when I approached ChatGPT for assistance. It recommended writing a Bash noscript to run the task using an ocrmypdf tool. I never wrote a noscript in my life, but I tried it. ChatGPT gave me the noscript, and as soon as I ran it, everything became really simple. Rather than handling every file separately, all I had to do was:

Put all the PDFs in one folder.
Run the noscript.
The noscript automatically produced an output folder and OCR'd all of them simultaneously.
It was an eye-opener experience. I had come to the realization that I could drastically decrease the effort spent manually doing these tasks and have a much more convenient life if I could do some basic Bash noscripting. If I am able to automate a single monotonous task, then likely several others, then hours worth of work can be saved down the road.

Where Should I Start Learning Bash Scripting?
I now understand the value of noscripting, and I would like to learn more and discover how to create my own automation noscripts. As I don't come from a programming background, I'm searching for the best beginner resources where I can start.

Would online video tutorials, books, or articles be the way to go? Do you have any suggestions for certain courses, books, or websites that one can learn Bash noscripting from scratch, and I'd be more than happy to hear them!

https://redd.it/1izlahs
@r_bash
why does rm remove "any-word*.any-ext" plus any-word01.any-ext?

**Hi**, I'd like to know why rm removes screen.jpg plus screen01jpg+screen##.... jpg **when I do rm any-word*.any-ext**?

rm screen*.jpg

*and this command deletes screen.jpg!*

how will be the command for not remove screen.jpg and yes screen01.jpg + screen02.jpg....

Thank you and Regards!

https://redd.it/1izsod6
@r_bash
I used xidel as a web scraper for scraping government job websites of Nepal (they're safe as they never update)

Can anyone recommend anything else? No problem with xidel though. I am on rocky 9

https://redd.it/1j03khv
@r_bash
was this a good case for automation

i had a task today - change old license agreement in 500 files in git repo. The problem was that there was no single template for license agrmt, various devs and teams wrote templates in all kinds of ways - short(4 lines) and long ( 20-50 lines) in several formats

here are templates, even varied by year:

/*

* Copyright (C) 2020 COMPANY NAME

* All Rights Reserved

*/

typical long full license header:

-- /*

-- * NOTICE: All information contained herein is, and remains

-- * the property of company_name and its suppliers,

-- * if any. The intellectual and technical concepts contained

-- * herein are proprietary to company_name and its suppliers

-- * and may be covered by U.S. and Foreign Patents, patents in

-- * process, and are protected by trade secret or copyright law.

-- /*



template 2:

/*

*

*

*

* copyright (c) company name

* All Rights Reserved

*

*

* NOTICE: All information contained herein is, and remains

* the property of company_name and its suppliers,

* if any. The intellectual and technical concepts contained

* bla bla bla

* bla bla bla

* bla bla bla

* from company_name.

*

/*

/*

* company (c) 2019 company name

* all rights reserved

*

*/

/*

* company (c) 2020 company name

* all rights reserved

*

*/

template 3:

/*

*

*

*2020 company_name.

* All Rights Reserved

* Copyright (C)

*

*

* NOTICE: All information contained herein is, and remains

* the property of company_name and its suppliers,

* if any. The intellectual and technical concepts contained

* herein are proprietary to company_name and its suppliers

* and may be covered by U.S. and Foreign Patents, patents in

* process, and are protected by trade secret or copyright law.

* Dissemination of this information or reproduction of this material

* is strictly forbidden unless prior written permission is obtained

* from company_name.

*

*

/

i cloned the repo

asked ai to write prompt to catch the files and remove the text using while loop + sed

and it did not work, then i just manually found all different templates based on "Copyright company_name" or variation of that and removed under 15 min ))


should i have done all the effort to write perfect bash noscript or i did it manually and it was good?

https://redd.it/1j0repw
@r_bash
How can it be both Link and Directory?

/bin/bash --version
GNU bash, version 5.2.37(1)-release (x86_64-pc-linux-gnu)
$ cat test1.sh
#!/bin/bash
mkdir -p dir
ln -sf dir link2dir
test -d dir && echo "dir is Directroy."
test -h link2dir && echo "link2dir is link"
test -d link2dir && echo "link2dir is Directroy"
$ ./test1.sh
dir is Directroy.
link2dir is link
link2dir is Directroy

https://redd.it/1j10hbg
@r_bash
Running a periodic copy noscript. Using cp -n because I don't want recursion. Get error as a result.

I have a noscript running that periodically sweeps a bunch of sftp uploads from branch offices. Each office has a /bleh/sftp/OfficeName/ dir, and an /bleh/sftp/OfficeName/upload/ subdir where files are uploaded to them. I don't need or want those copied back to where I'm processing these other files they've uploaded back to me, so I use the command

cp -n /bleh/sftp/OfficeName/ /opt/crunchfiles/officecode/

Which gives the desired result, omitting the contents of the upload/ subdir. However, I receive the output:

cp: -r not specified, omitting directory '/bleh/sftp/OfficeName/upload'

To which I have taken to replying "NO SHIT! That's what you are supposed to be doing, it's not an error or misconfiguration, it's an intentional use of switches to get the result I want!"

Redirecting the output to /dev/null as in

cp -n /bleh/sftp/OfficeName/
/opt/crunchfiles/officecode/ 2>/dev/null

works to suppress the message, but the noscript still exists with error code 1, which means it still shows up as a failure in my orchestrator. How can I avoid the error code and tell it to just copy the files specified by the switches and stop messing me up with my metrics?

https://redd.it/1iyt79j
@r_bash
FUNCNAME array with some empty values

Hi,

I'd like to print an error message displaying the call stack from a specific function that is passed an error message, the specific function having to display the call stack plus the error message

I thought I could use FUNCNAME array within that function
Strangely though, FUNCNAME array has 20 values, the 16th last being empty ...
Thus I can't use FUNCNAME length to determine the main noscript filename that would be ${BASH_SOURCE[${#FUNCNAME}-1\]} and output the names in FUNCNAME array from first to penultimate value.

Of course, it's possible to get the last index which value is not empty, but I'd like to understand why FUNCNAME lists those empty values.

Thanks for your help !

https://redd.it/1j23zsk
@r_bash
Notifications in the terminal

Hello, I wanted to make a command that would print out desktop notifications in the terminal, by using tail -f on the notification log file.

>tail -f /home/user/.cache/xfce4/notifyd/log | grep -E "app_name|summary|body"

works as intended, i get the response:

>app_name=notify-send

>summary=1234

>body=

>app_name=notify-send

>summary=test2

>body=

But when i add awk, to only print out the content after the equals sign I get no response. The command is running but it's returning nothing.

>tail -f /home/user/.cache/xfce4/notifyd/log | grep -E "app_name|summary|body" | awk -F'=' '{print $2}'

with set -x I get:

>+ tail -f /home/user/.cache/xfce4/notifyd/log

>+ grep -E 'app_name|summary|body'

>+ awk -F= '{print $2}'

I tried making a noscript with a while expression instead of awk, again no output.

>#!/bin/bash

># Path to the log file

>LOG_FILE="/home/user/.cache/xfce4/notifyd/log"

># Tail the log file, filter lines, and extract content after the equals sign

>tail -f "$LOG_FILE" | grep -E "app_name|summary|body" | while IFS='=' read -r key value; do

>echo "$value"

>done

I honestly don't understand where the issue is. Any help is much appreciated.

https://redd.it/1j1z23q
@r_bash
what did I do wrong

 \#!/bin/bash

[ttjz8b@delmar \~\]$ echo Name,phoneNumber,Expense1,Expense2,Expense3 > move1.csv

[ttjz8b@delmar \~\]$ cat data.csv >> move1.csv

[ttjz8b@delmar \~\]$ grep "\^S.*r," data.csv | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' > move2.txt

[ttjz8b@delmar \~\]$ grep "(777)" data.csv | sed 's/.* \\([\^,\]*\\),.*/\\1/' > move3.txt

[ttjz8b@delmar \~\]$ grep ",.* [ES\]" data.csv | sed 's/\\([\^ \]*\\) .*/\\1/' > move4.txt

[ttjz8b@delmar \~\]$ grep ',\\$[0-9\]\\{2,\\}\\.[0-9\]\\{2\\},' data.csv | sort -t ',' -k 1.2 | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' > move5.txt

[ttjz8b@delmar \~\]$ grep ',\\$[0-9\]*\\.[0-9\]\\{2\\},.*,\\$[0-9\]\\{2,\\}\\.[0-9\]\\{2\\},' data.csv | sort -t ',' -k 1.2 | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' >> move5.txt

[ttjz8b@delmar \~\]$ grep ',\\$[0-9\]*\\.[0-9\]\\{2\\},.*,.*,\\$[0-9\]\\{2,\\}\\.[0-9\]\\{2\\}$' data.csv | sort -t ',' -k 1.2 | sed 's/\^\\([\^,\]*\\),\\([\^,\]*\\),.*/\\1,\\2/' >> move5.txt

[ttjz8b@delmar \~\]$ sort -u move5.txt -o move5.txt

[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^A[A-Z\]* ,' | sed 's/,.*//' > move6.txt

[ttjz8b@delmar \~\]$ 

[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^E[A-Z\]* ,' | sed 's/,.*//' >> move6.txt

[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^I[A-Z\]* ,' | sed 's/,.*//' >> move6.txt

[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv | grep '\^O[A-Z\]* ,' | sed 's/,.*//' >> move6.txt

[ttjz8b@delmar \~\]$ tr '[:lower:\]' '[:upper:\]' < data.csv| grep '\^U[A-Z\]* ,' | sed 's/,.*//' >> move6.txt

[ttjz8b@delmar \~\]$ sort -u move6.txt -o move6.txt

[ttjz8b@delmar \~\]$ tail -n +2 move1.csv | perl -F',' -lane '($a,$b,$c)=map{s/\\$//;$_}@F[2,3,4\]; $max = $a>$b ? ($a>$c?$a:$c) : ($b>$c?$b:$c); printf "%s,\\$%.2f\\n", $F[0\], $max;' > move7.txt

[ttjz8b@delmar \~\]$ chmod +x transform.sh

[ttjz8b@delmar \~\]$ /transform.sh data.csv

\-bash: /transform.sh: No such file or directory

[ttjz8b@delmar \~\]$ ls

1         info.shmove2.txt  move5.txt  move.txt       output

data.csv  move1.csv  move3.txt  move6.txt  multiline.txt  transform.sh

file.csv  move1.cv   move4.txt  move7.txt  number         where

[ttjz8b@delmar \~\]$ /transform.sh data.csv

\-bash: /transform.sh: No such file or directory. what did I do wrong

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