r_bash – Telegram
I have a copy of this book, is it worth studying this end to end?
https://redd.it/1nux1tf
@r_bash
bash noscript that can detect all individual keystrokes?

I'm talking all individual keystrokes. Obviously, if you can open a pipe in a raw form, then stroking a glyph key will generate byte of data into the pipe. But what about the arrow keys? In the Linux console/GNOME Terminal, they generate ANSI escape codes, which, again, in raw read mode should be immediately available. But then, there are the modifier keys.

Is there any way that a bash noscript can reopen the terminal such that even stroking Alt, or Ctrl, or Shift individually can be detected?

https://redd.it/1nw4j9j
@r_bash
Space in file (Space in this filename bandit lvl2 .)
https://redd.it/1nwtofq
@r_bash
Read systemd env file

I have a systemd environment file like:

foo=bar


I want to read this into exported Bash variables.

However, the right-hand side can contain special characters like $, ", or ', and these should be used literally (just as systemd reads them).

How to do that?



https://redd.it/1nx63dy
@r_bash
NLP using Bash jq & Nix

Is this too Nix for you guys or agree it's dope?

https://quackhack-mcblindy.github.io/blog/

https://redd.it/1nxlssd
@r_bash
How to learn bash noscripts?

I have been really wanting to learn bash noscripts but I’m just not sure where to start. I already know the basics like variables, if, functions. Also this is an example noscript that I want to learn to be able to make it’s just noscript that fzf searches my tmuxifier layouts a remove the one I pick.

https://redd.it/1nxxlce
@r_bash
Desperately need a tutor/HOWTO create automated bash-completion test (for scientific research project)

Hi,

I've created some 700 iterations of a bash-completions noscript for a scientific research project. To date, I've been manually testing, but this is taking FOREVER and is brittle.

I just can't seem to figure out either simulate a TAB keypress in the CLI via Bash nor how people do automated testing for bash-completions, or if it's even possible.

Please, I've been struggling for days and am blocked.

Your assistance can be directly cited in the research project if you want.

https://redd.it/1nydoa8
@r_bash
how to process text with quotes and backslashes

I wrote a noscript to turn a .csv file into a list of Powershell commands to add user accounts to a PC.
Let me say right up front that I know very little about the Windows command line.
And also that my noscripting skills are self-taught so please be merciful.

_______________________

Here's the (anonymized) noscript:

#!/bin/sh

## run this noscript with the input file as argument
## requires csvkit

csvcut=/opt/homebrew/bin/csvcut ;
tmpfile=/tmp/laserUsers.txt ;
myDate=$(date '+%Y.%m.%d%k.%M.%S') ;
outputfile=
$HOME/Documents/laser-users-add-batch-"$myDate".txt ;

backslash='\' ;
quote='"' ;

: > $tmpfile ;

## extract emails from downloaded .csv file, delete domain name & convert to lowercase
$csvcut -c "Email Address" "$1" | tail -n+2 | sed 's/
@soul.com//g' | tr '[:upper:]' '[:lower:]' >> $tmpfile ;

## build userlist
while read thisuser ; do
echo "net.exe localgroup "$quote""lasercutterlogin""$quote" "$quote""MS"\\"$thisuser""$quote" /add" >> $outputfile ;

done < $tmpfile ;

\
______________________

And here's a sample input .csv file:

Badge Identity,Email Address
George Clinton,gclinton@soul.com
Ndea Davenport,ndavenport@soul.com
Aretha Franklin,afranklin@soul.com
Bootsy Collins,bcollins@soul.com
Ray Charles,rcharles@soul.com
Tina Turner,tturner@soul.com

_______________________

When I run it, output file looks like:

net.exe localgroup "lasercutterlogin" "MS\gclinton" /add
net.exe localgroup "lasercutterlogin" "MS
davenport" /add
net.exe localgroup "lasercutterlogin" "MS<0x07>franklin" /add
net.exe localgroup "lasercutterlogin" "MS <0x08>collins" /add
net.exe localgroup "lasercutterlogin" "MS
charles" /add
net.exe localgroup "lasercutterlogin" "MSturner" /add

The first line (gclinton) is processed correctly. That's what they should all look like.

The rest of the lines are malformed because (for example) "backslash - rcharles" is rendered as "newline charles".

I get why this is happening but haven't figured out how to fix it! There must be a better way to write line 17, ideally without creating variables called "backslash" and "quote".

Humbly awaiting any quidance .... thanks!

https://redd.it/1nzroy2
@r_bash
Script Evaluation

I wrote a shell noscript for Fedora optimization after a fresh install. Please can someone go over it and tell me where I can improve on it.

The noscript: https://github.com/somniasum/crimsonhat/blob/main/crimsonhat.sh
Thank you in advance.

https://redd.it/1o0b8yb
@r_bash
rofi, mpc music noscripts with "&" always play #1 in position

my noscript is a bit of a mess, as i was trying different ways to do it, but couldn't wrap my head around it.

the problem was without $escaped\_list, rofi wouldn't display any music containing "&". now it displays them, BUT whenever I select one with that character, it always plays the song with #1 in %position%. for other songs it works perfectly, though

#!/usr/bin/zsh

current=$(mpc current)

songs=$(mpc playlist --format "%position% - %artist% - %noscript%")

positionless_list=$(echo "$songs" | sed 's/^[0-9]* - //')

escaped_list=$(echo "$positionless_list" | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' -e 's/"/\&quot;/g' -e "s/'/\&apos;/g")

shuffled=$(echo "$escaped_list" | shuf)

selection=$(echo "$shuffled" | rofi -dmenu -i -p "$current" -markup-rows)

if [ -n "$selection" ]; then

original_line=$(echo "$positionless_list" | grep -F "$selection" | head -n1)

pos=$(echo "$songs" | grep -F "$original_line" | head -n1 | awk '{print $1}')

mpc play "$pos"

fi

https://redd.it/1o0jby1
@r_bash
Bandit Level 6 → Level 7 plz help bro .. . .. . . .. . .
https://redd.it/1o0jj9f
@r_bash
why?

First git pull --rebase and then git push. Why use rebase instead of a normal merge? What are the risks if there are conflicts?

https://redd.it/1o0vvm1
@r_bash
Rename files with inconsistent field separators

Scenario: directories containing untagged audio files, all files per dir follow the same pattern:

artist - album with spaces - 2-digit-tracknum noscript with spaces

The use of " " instead of " - " for the final separator opens my rudimentary ability to errors.

Will someone point me towards learning how to process these files in a way that avoids falses? I.E. how to differentiate [the space that immediately follows a two-digit track number] from [other spaces [including any other possible two-digits in other fields]].

This is as far as I have gotten:

for file in *.mp3
do
art=$(echo "$file" | sed 's,\ \-\ ,\n,g' | sed -n '1p')
alb=$(echo "$file" | sed 's,\ \-\ ,\n,g' | sed -n '2p')
tn=$(echo "$file" | sed 's,\ \-\ ,\n,g' | sed -n '3p' | sed 's,\ ,\n,' | sed -n '1p')
titl=$(echo "$file" | sed 's,\ \-\ ,\n,g' | sed -n '3p' | sed 's,\ ,\n,' | sed -n '2p')
echo mv "$file" "$art"_"$alb"_"$tn"_"$titl"
done

Thanks.

https://redd.it/1o10dff
@r_bash
Check my timestamp check please

Hi,

I need to check how dumb I am.

I have files arriving every day and I have some checks running on those files named FILENAMEXYZ_timestamp.csv with the current date timestamp.

ls $DIR/FILE*$(date '+%y%m%d')*

I don't need the $ do I? I'm currently checking for a file containing a string contained in the variable named <timestamp>, aren't I?

https://redd.it/1o1bbg9
@r_bash
Small function for faster directory navigation
https://redd.it/1o2guya
@r_bash
Is Bash programming?

Since I discovered termux I have been dealing with bash, I have learned variables, if else, elif while and looping in it, environment variables and I would like to know some things

1 bash is a programming language (I heard it is (sh + noscript)
----
Is 2 bash an interpreter? (And what would that be?)
----
3 What differentiates it from other languages?
----
Is 4 bash really very usable these days? (I know the question is a bit strange considering that there is always a bash somewhere but it would be more like: can I use bash just like I use python, C, Java etc?)
-------
5 Can I make my own bash libraries?
------
Bash is a low or high level language (I suspect it is low level due to factors that are in other languages ​​and not in bash)

https://redd.it/1o2le8n
@r_bash
Cool looking prompt. How to enable it?
https://redd.it/1o3cw68
@r_bash
How do i setup bash LSP in neovim?

I wanted to learn some bash. Then i thought it would be nice to have some auto-completion along the way. I'm on lazy.nvim, so the lsp installation was easy. I think everything works fine, except for i cant autocomplete #!/usr/bin/env bash. Any fix?

https://redd.it/1o3oxue
@r_bash
Am I being inefficient with this copy function I made?

Sometimes I want to copy a file to a directory with a really long path. To save myself having to write out the path for cp, I wrote a copy function that will move the file or directory into a clipboard folder that I created, and a paste function that will move the file or directory from that clipboard directory to my current working directory. So, if I’m in that destination directory with the long path, I can pushd, cd to the file/directory, copy the file, popd, and paste the file. It’s a lot of operations, but they’re all short, and I don’t have to type out that long path. Am I being silly?

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