r_bash – Telegram
Rookie question Getting the noscript report.

Hello community!

​

I wonder if there is any possibility to make a statement in the bash noscript which create a report of recent changes in it and for example send a notification via e-mail? Is this even possible to do in bash, without any external plugins?

https://redd.it/zpx29b
@r_bash
How to enforce stdout=PIPE in bash without cat?

Sometimes I want to ensure, that stdout is a pipe as this may change the behavior of a program in a wanted way. E.g. more has a nice side effect when it sends output to a pipe instead of a terminal: It adds the file noscript - embedded in lines with colons - to the output. Hence a command like the following is a quick hack to generate an overview in the output:

more /etc/cron.d/* | cat

I‘m just curious: Does anybody knows another - easy to type - method, how to trigger this output mode of more?

https://redd.it/zq1gn4
@r_bash
I have a programming question :)

Hey fellas,

I'm on the quest to kind of automate my semester in terms of checking due dates and such things of that nature. Is there a way that I could grab the due dates that are posted to the website that holds my assignments and stuff? Like, for example:

​

I would like to have a noscript that runs with cron every so often (That part I know how to do) and have it send me a desktop notification saying y'know.. something like "You have a math final due..... blah blah".

I know the wget command does things with websites and HTML and all that good stuff, but is there a way to do what I wanna execute within the command line?

​

Ps: I am doing this strictly for fun :D because I have a newfound love for the linux command line because of its flexibility

so any fun ways to do this, please let me know!

https://redd.it/zq3ugq
@r_bash
pass (password manager) autocompletion for items

I would ask question about pass. Is it a way to autocomplete in the bash in that way do not type parent directory name?

For example structure is

\- directory
   \- password1
   \- password2

If I want password1 pass I have to type firstly the parent directory name.

Basically I can't type pass TAB and get password1 or password2 suggestions.

For now I'm using noscript providing by pass developers https://git.zx2c4.com/password-store/tree/src/completion/pass.bash-completion

https://redd.it/zq3tim
@r_bash
How to do a noscript check with adb devices

Hi, I'm trying to figure out a good way to add a check in my noscript with adb devices to see if any Android device exists before running my noscript further with more adb commands.

Currently, When I try a check like this:

   if ! adb devices; then
...
exit
fi


But it doesn't work that way. It's not designed very noscripting friendly. It doesn't even output a different ERRORLEVEL if a device is attached or not, it just outputs a string like "List of devices attached\n" then exits.

I already have a feeling piping into sed is needed here, so then I can test with [ -z $(CMD | sed "blah") ]. but I am TERRIBLE at figuring out the right sed lines to do this. So if anyone can help, that would be great.

I am actually using dash (Debian shell), so I'd prefer something POSIX sh compliant, but if I have to use bash, that's fine. IDK if there's a Subreddit for POSIX sh noscripting, but would like to know. :)

https://redd.it/zqb2xw
@r_bash
How do you put the content of a folder inside a tar file?

I tried:

​

tar -cvzf a.tar.gz a

​

and it didn't work. Is there a way to put them inside a tar.gz file without compressing the files? I am not sure what's wrong but my filereader doesn't work when I read the tar.gz file even if the content is the same. I am basically creating a tar.gz file and then extracting the content and then running the bash command with the extracted content to see if my filereader can still read the file, but apparently the files aren't the same and my filereader can't read the created tar, even if it can read the first tar generated through my app.

https://redd.it/zqdhm8
@r_bash
Does a Gruvbox theme exist for Bash?

Looking for a gruvbox theme for bash. And maybe konsole, as I use plasma.

https://redd.it/zqimzm
@r_bash
get user input and add it to an ffmpeg screen recording

I have the following noscript added as aliases in bash

today=`date '+%d_%m_%Y-%H_%M_%S'`;
filename="/tmp/$today.mp4"
alias srec='ffmpeg -f x11grab -video_size 1600x900 -framerate 25 -i $DISPLAY -f alsa -i default -c:v libx264 -preset ultrafast -c:a aac ${filename}'

it records the screen and saves the file to /tmp with todays date.

how can I make it ask for input and it after the date and before the file extension of the video

example:

20-12-2022-{video}.mkv

https://redd.it/zqj63a
@r_bash
curl not finding the file

I made this short noscript

pic_name= "$HOME/Screenshots/$(date +%s).png"

maim -s $pic_name

url= $(curl -F'file=@$pic_name' https://0x0.st)

echo $url | xclip -sel clip

dunstify "File Uploaded" "URL: $url \ncopied to clipboard" -t 5000 -i "$HOME/.config/dunst/images/success.png"

but it's not pushing the screenshot to 0x0 any clue?

https://redd.it/zqk5ax
@r_bash
When using echo, both ${pwd} and $pwd work, does it matter which you use?

They both seem to be working. I know the {} is used for arrays but I want to ask whether there is a reason to use one over the other when echoing.

https://redd.it/zr2552
@r_bash
rgb/hex converter syntax - how does this work?

Hi All.

I'm preparing a wrapper noscript around these snippets I found that convert rgb to hex and hex to rgb. I eventually want to expand it so that it also converts the alpha channel, but I don't quite understand the syntax. Could someone please break down how these following two functions work:

​

hextorgb() {
: "${1/\#/}"
((r = 16#${:0:2}, g = 16#${:2:2}, b = 16#${:4:2}))
printf '%s\n' "rgb($r, $g, $b)"
}

rgb
tohex() {
printf '#%02x%02x%02x\n' "$1" "$2" "$3"
}


Any insights into what is happening here, particularly in hex\
to_rgb(), would be

greatly appreciated. Thanks in advance.

https://redd.it/zqmvz8
@r_bash
Guidance with homework

I am a beginner and would like some help with an exercise:

Generate 100 files containing one random number each. Scan the files and find the 5 files that have the highest numbers and the 5 files that have the lowest numbers. Write the numbers you receive in a "list.txt" file.

I have already completed the beginning of generating the files.

for x in $(seq 1 100)

do

shuf -i 1-1000 -n 1 -o $x.txt

done

I am uncertain of how to sort the 100 files by what's actually written inside each of the files. This is a written example of how I imagined I could do the rest of the exercise, but I don't actually understand how to put it all together:

for x in $(seq 1 5)

do

for x in $(seq 1 100)

do

#find largest number in files out of the directory

#find lowest number in files out of the directory

#move both of the numbers to list.txt

#remove both of the files out of the directory

#repeat the process by moving and removing the files

done

done

Would this work? Do I need to use head and tail to find the needed values? Sorry if this isn't enough info.

https://redd.it/zrg7o2
@r_bash
Dead-simple command-line options for small noscripts. Specify all your options on a SINGLE line. Live option values are available as environment and shell variables.
https://gist.github.com/fareedst/8979cc7bd9c811ecd450b9be6d511cdf

https://redd.it/zrxzmd
@r_bash
remove all files that contain numerical string in filename?

Is there an ideal way to remove all files in a directory that are within a certain numerical range?

I have tried using both find and rm but the issue i run into is that the numbers are seperated by periods in the file name so i can't do something like:

rm {5..2}

I know I can just run multiple commands like:

find -type f -name '.6' -delete

but find this inefficient!

https://redd.it/zskhq6
@r_bash
I don't understand how bash -c and sh -c work in regard to keybinding

Hello everybody, I have a little noscript that I launch from the terminal to close my current Firefox session open my VPN connection, kill ipv6, so it doesn't rat out my real IP and then start a new FF instance in my VPN profile.

I wanted to make my life a little easier and bind the noscript to a key, and I accidentally felt into a rabbit hole.

The problem is that killing off ipv6 requires sudo permission. So after I press the keybinding (let's say super +v) I want to be prompted by a GUI asking me for my sudoer password.

This is my_noscript that I launch from the terminal, and it works fine, after I call it from the command line I get prompted for my password inside the terminal:

\#!/bin/bash

​

>pkill -f firefox
>
>sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
>
>sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
>
>sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
>
>nmcli con up id " ......"
>
>firefox --detach -P "my_vpn" &
>
>pkill terminator

terminator is my terminal emulator.

I tried to just associate this noscript to a key, but obviously I don't get prompted for my sudoer password. So after a day of searching online, I still can't make it work.

I tried associating the super+v to the following command : sh -c "pkexec new_noscript"

where the new_noscript is:

>\#!/bin/bash
>
>pkill -f firefox
>
>sysctl -w net.ipv6.conf.all.disable_ipv6=1
>
>sysctl -w net.ipv6.conf.default.disable_ipv6=1
>
>sysctl -w net.ipv6.conf.lo.disable_ipv6=1
>
>sudo -u "my_username" nmcli con up id "..."
>
>/usr/bin/firefox --display="127.0.0.1:10.0" -P "my_vpn"

So I get a GUI prompt asking me for my sudoer password, ipv6 is turned off, my VPN is launched (well at first it was complaining about no VPN secrets, which sounded interesting because I kind of like secrets, but in the end I figured it was just a problem that I was launching nmcli through the root account hence the sudo -u to go back to my normal user account), but Firefox won't launch. The noscript works when started from an interactive bash shell but not as a keybinding, so I guess some x11 variable isn't being passed on.

I tried export DISPLAY=localhost:0.0 before the Firefox line, but I'm just guessing here, I don't really understand what is going on. I would also like in the future to make the noscript more robust, by using ufw as a kill switch.

Can somebody please explain why I can't use bash -c "pkexec command" when associating a keybinding, but I can with sh -c. The OS is Linux Mint cinnamon DE (fork of gnome).

And what exactly does the -c option does. I do not understand it. The bash manual starts with it, really depressing stuff. From a historical point, what exactly does that "c" stand for?

https://redd.it/zspdv5
@r_bash
my noscript to preview all images in a directory (any suggestions?)

Hello,

I have this short noscript that can provide a preview of all images in a directory:

#

for file in *

do

if [[ $file =~ \.jpg$|\.jpeg$|\.png$|\.gif$ ]]

then

kitty +kitten icat --align="left" --background="#1e1e2e" --loop="-1" "$file"

echo "$file"

fi

https://redd.it/zsqwei
@r_bash
Two-Way Mapping/Hashing

Hi folks,

I've got a use-case where I'm wanting to take a user input, and map it to a JIRA ticket reference (it looks something like ABC-1 where the number will vary depending on the user input.

This is fine, I've done it with an associative array (i.e. "${myMap[taskA]}" will return, say, ABC-2).

What I also then want to do is take ABC-2 and get back a human-understandable format, i.e. Task A.

I can't think of a way to do a two-way map without just defining a second associative array, which then leaves me with 2 arrays that contain almost the same data, which is less than ideal!

If anyone has any suggestions, I'd very much appreciate it.

https://redd.it/zsq4mv
@r_bash
I need a sanity check on my function to find installed editors.

For my command line tool ([https://github.com/membersincewayback/gen](https://github.com/membersincewayback/gen)) I recently added a check for installed editors when a user doesn't have \`$EDITOR\` defined. It works, but I just want to make sure I'm not missing something obvious:

which_ed() {
while IFS= read -r file; do
case "$file" in
*/emacs) EDITOR="/usr/bin/emacs"; return ;;
*/mc) EDITOR="/usr/bin/mc"; return ;;
*/micro) EDITOR="/usr/bin/micro"; return ;;
*/nano) EDITOR="/usr/bin/nano"; return ;;
*/ne) EDITOR="/usr/bin/ne"; return ;;
*/nvim) EDITOR="/usr/bin/nvim"; return ;;
*/vim) EDITOR="/usr/bin/vim"; return ;;
*/vi) EDITOR="/usr/bin/vi"; return ;;
esac
done < <(find /usr/bin)
}

This should exit the function when it matches, and the \`find\` seems to be alphabetical, so there's likely no point in having every possible editor, only enough to guarantee a match. (this is also why 'ED" isn't included.)

https://redd.it/zt12qi
@r_bash