r_bash – Telegram
Add timestamp to stderr redirect

I'm running a noscript on my machine that displays a bunch of junk as it runs. I pipe that junk into /dev/null because I don't care what it says and I capture any errors in a file (I only care if the noscript doesn't run), however, the errors don't come with a time stamp. Is there a way to append a timestamp to the stderr redirect? This is the command I have, but can't figure out how to add the timestamp:

myScript.sh 2>> logfile.txt 1>/dev/null

I can't modify myScript.sh to print a date so that's not an option either. I tried something like this:

myScript.sh 2>> logfile.txt << date

but that doesn't work.

https://redd.it/142fbfs
@r_bash
Temporary symlink in shell - "named process substitution" - rename a file without creating a copy/symlink on the disk?

Thunderbird doesn't open files that don't have .eml extension as email files, but instead starts to compose a new message and adds them as attachments. To use thunderbird in noscripts I'm looking for a way that would allow you to "temporarily rename" a `file` as a `file.eml`, open it in thunderbird (possibly edit, but at least read) and close it without saving anything to the disk.

While this could be achieved by either copying or creating a symlink to that file there are many elegant ways to use process substitution or here strings that instead create "temporary files" that live only for duration of the process.

Is there anything that could create such "pseudo symlinks" in bash/zsh?

https://redd.it/142srw1
@r_bash
Career Question

Sorry if this is the wrong place to post but just genuinely curious and heck there may be somewhere out there in a similar position.I currently work in tech for a large company as a tech support engineer. Its a "good" job in terms of benefits, PTO, Salary is just about six figures however I am over tech support. I have been doing some for of tech support the last 5 five years and am looking to make a pivot or at least a bigger jump in salary. My natural passion leads me to UX research/design.

I don't have a portfolio or direct UX experience yet so breaking in to that type of role is a strectch. Currently I am working on a Google UX certificate but in the interim I would like to leverage some of the skills I have gathered and increase my salary. My question is about the command line. I am pretty well versed in the Linux Bash Shell / MacOs terminal / command line as my day to day involves me scraping support logs for trouble shooting purposes.

Are there any roles, certs or career progressions you would recommend for someone in my position? I do not want to corner myself as a career long tech support engineer and would like to leverage my bash/mac os/Zsh terminal knowledge, is it possible any tips? What are some specific careers, anything tech related, that terminal/bash skills would be really helpful in? I do not necessarily expect any high paying jobs to hire me based on terminal usage alone, so obviously, you can recommended careers where I'll have to learn more. I have a few certs from Coursera, Udemy related to linux bash, Mac OS terminal as well as a VMware VCP Unified endpoint management certification. Thanks guys.

https://redd.it/14343st
@r_bash
Unbind ctrl+l from clearing terminal

I'm trying to unbind ctrl+l from clear and trying to bind Ctrl + shift + l to it.

So far I could come up with this which is apparently not working:

bind -r "\C-l"
bind -x '"C-L":clear'



https://redd.it/1439tlq
@r_bash
Convert an if/else to case statement

I have this if/else chain and think it could be probably better off as a case statement but could use some pointers on evaluating the array vars.

Any tips/pointers would be much appreciated

if [[ -n "${CHAIN3[0]}" ]] ; 
then
printf "\t %s\n %s %s %s %s %s\n\n" \
"Evolution Chain" "${CHAIN1^}" "►" "${CHAIN2^}" "►" "${CHAIN3^}";
elif [[ -z "${CHAIN2[0]}" ]] ;
then
printf " %s\n\n" "Single Stage Evolution Pokémon";
else
printf "\t%s\n %s %s %s\n\n" \
"Evolution Chain" "${CHAIN1^}" "►" "${CHAIN2^}";
fi;
if [[ ${#CHAIN1[@]} -gt 1 ]] ;
then
printf "%s:\n" "Stage 1 Forms";
for ((i=0; i<${#CHAIN1[@]}; i++)); do
printf " %s\n" "${CHAIN1[i]}";
done;
printf "\n";
fi;
if [[ ${#CHAIN2[@]} -gt 1 ]] ;
then
printf " %s:\n" "Stage 2 Forms";
for ((i=0; i<${#CHAIN2[@]}; i++)); do
printf " %s\n" "${CHAIN2[i]}";
done;
printf "\n";
fi;
if [[ ${#CHAIN3[@]} -gt 1 ]] ;
then
printf " %s:\n" "Stage 3 Forms";
for ((i=0; i<${#CHAIN3[@]}; i++)); do
printf " %s\n" "${CHAIN3[i]}";
done;
printf "\n";
fi;


https://redd.it/143e4y4
@r_bash
Can you remap ctrl+h and ctrl+backspace differently

I recently started using tmux vim navigation, so the previous C-h mapping I had to backward kill word is not working anymore.

Clicking C-bak used to trigger the C-h mapping before. But since tmux is remapping C-h, C-bak word kill is not working anymore

https://redd.it/143d43s
@r_bash
How to remove all <br> from all of my .html files

I have about 300 html files and on 50 of them ive unneccesarily added some <br> in some places... and now those <br> are causeing me some trouble... is there a shell noscript where i can look trough all of my files that end with .html and remove all <br> words (not the entire line, just <br>)

https://redd.it/14441a1
@r_bash
Here comes penis

Hi Reddit people!)
Working on my piu-piu project trying to make it to the Mars. But the journey is long so I've decided to make something quick and fun in-between... Penis mode!)

single mode

If it's not enough fun, ask a friend to join and start ~~DP~~ team play together!) Yeah it's always more fun with two barrels!)

team play

Or try to ~~cum~~ shoot each-other in duel mode. Who's got the biggest member? And most hairy balls?) Let's find it out here and now!)

duel mode

Download the game here and run it like this to enter the penis mode:


penis=big ./piu-piu


Have fun)

https://redd.it/144bxky
@r_bash
Using select with command output

I have a directory that looks like this:


[\ #2] ls
2 file.mp3 6 file.mp3 9 file.mp3 13 file.mp3 20 file.mp3
1 file.mp3 5 file.mp3 16 file.mp3 12 file.mp3 19 file.mp3
8 file.mp3 4 file.mp3 15 file.mp3 11 file.mp3 18 file.mp3
7 file.mp3 3 file.mp3 14 file.mp3 10 file.mp3 17 file.mp3

I can run `select` to make a quick menu:

[\ #3] select mp3 in *mp3; do echo "$mp3"; done
1) 10 file.mp3 6) 15 file.mp3 11) 1 file.mp3 16) 5 file.mp3
2) 11 file.mp3 7) 16 file.mp3 12) 20 file.mp3 17) 6 file.mp3
3) 12 file.mp3 8) 17 file.mp3 13) 2 file.mp3 18) 7 file.mp3
4) 13 file.mp3 9) 18 file.mp3 14) 3 file.mp3 19) 8 file.mp3
5) 14 file.mp3 10) 19 file.mp3 15) 4 file.mp3 20) 9 file.mp3
#? 8
17 file.mp3
#?

What has me blocked is I can't figure out how to use a command like `ls *mp3` in the select. When I try

select mp3 in $(ls *mp3); do echo "$file"; done

I get:

1) 2 9) 6 17) 9 25) 13 33) 20
2) file.mp3 10) file.mp3 18) file.mp3 26) file.mp3 34) file.mp3
3) 1 11) 5 19) 16 27) 12 35) 19
4) file.mp3 12) file.mp3 20) file.mp3 28) file.mp3 36) file.mp3
5) 8 13) 4 21) 15 29) 11 37) 18
6) file.mp3 14) file.mp3 22) file.mp3 30) file.mp3 38) file.mp3
7) 7 15) 3 23) 14 31) 10 39) 17
8) file.mp3 16) file.mp3 24) file.mp3 32) file.mp3 40) file.mp3
#? ^C

OK. I figure just stupid me not quoting the variable once again, so I quickly edit and try:

select mp3 in "$(ls *mp3)"; do echo "$file"; done

And I get:

1) 2 file.mp3
1 file.mp3
8 file.mp3
7 file.mp3
6 file.mp3
5 file.mp3
4 file.mp3
3 file.mp3
9 file.mp3
16 file.mp3
15 file.mp3
14 file.mp3
13 file.mp3
12 file.mp3
11 file.mp3
10 file.mp3
20 file.mp3
19 file.mp3
18 file.mp3
17 file.mp3
#?

which isn't correct either. I'm sure it has something to do with bash and arrays or lists or something, but I'm just banging my head against a wall here.

https://redd.it/144lwgg
@r_bash
What does the second line do?

noscriptdir="$(dirname "$0")"
noscriptdir="$(cd "$noscriptdir" && pwd)"

First line sets the variable to the directory the noscript is in. Second line...does it again in a different way? What does this do and when would it matter?

https://redd.it/144wyog
@r_bash
Need help using a text file as input for case selection.

I have the data I need gathered from df of available drives (data is exactly the same as the output for a df query just sorted and individually placed into arrays for comparisons, and a $(printf '\t')between each of the elements) and all the data sorted into arrays. I have the data of each drive going into a text file, one drive, all data, per line. What I'm wanting to do is use this text file within a case statement to choose which to do an rsync to that particular chosen drive, and I will add one additional statement to sync to all drives that have the capacity to hold the data (which is why I needed the comparison ability).

I just can't figure out how to read the file into the case and use that as the array for the menu selection to choose the drive to rsync to.

I will use this information to forward data to the rsync command if I can just figure out how to use this text file to construct the case statement itself for the menu. Thanks

https://redd.it/145b9fa
@r_bash
r/bash will go dark from 12-14 June in protest against Reddit API price changes

Dear r/bash users,

As most of you have already heard by now, Reddit’s new API price changes will have a severe detrimental impact on third-party apps, essentially forcing them to shut down. If you use a third-party app to browse Reddit, you will no longer be able to do so starting 1st July.

Furthermore, because Reddit’s native app is not designed to accommodate people with visual impairements, starting 1st July they will be forced to either quit using Reddit altogether, or switch to Old Reddit on desktop, which might eventually face shutdown too.

In protest against this, we decided to join a growing list of subreddits and make r/bash private for the period of 12-14 June, meaning you will not be able to access the subreddit during this time.

https://redd.it/145esyf
@r_bash
Need help with a noscript

hello friends I am currently trying to solve this "

1. if a number is divisible by 3, print "SMILE" instead of the number.
and after a few hours of trying have figured I need to ask for help if you can that would be much appreciated thanks.

https://redd.it/145sdj0
@r_bash
Running weekly average

I think I may be getting way out of my ability here. If I have a file that looks like this:

data.txt:

Day Data
1 29
2 37
3 20
4 24
5 33
6 29
7 11
8 40
9 31
10 36
11 15
12 41
13 47
14 17
15 46
16 16
17 37
18 21
19 39
20 12
21 44
22 35
23 20
24 26
25 41
26 13
27 41
28 14
29 20
30 47

I would like to add a running average of the previous 5 days. So that given the data file, I would output:


Day Data Running 5 day average
1 29
2 37
3 20
4 24
5 33 28.6
6 29 28.6
7 11 23.4
8 40 27.4
9 31 28.8
10 36 29.4
11 15 26.6
12 41 32.6
13 47 34
14 17 31.2
15 46 33.2
16 16 33.4
17 37 32.6
18 21 27.4
19 39 31.8
20 12 25
21 44 30.6
22 35 30.2
23 20 30
24 26 27.4
25 41 33.2
26 13 27
27 41 28.2
28 14 27
29 20 25.8
30 47 27

This is pretty trivial using a spreadsheet, but I would like to be able to do it with awk, or datamash (or whatever), but I can't seem to wrap my head around it. The logic is just add today's data to the previous 4 days and divide by 5.

https://redd.it/146abdr
@r_bash
My bash module framework now supports interfaces and inheritance
https://m10k.eu/2023/06/10/toolbox-interfaces.html

https://redd.it/146mgxn
@r_bash
Modules, frameworks, libararies

What is everyone's thoughts on modules/libraries/frameworks for bash? Oftenly people share their new custom library, mostly written in improper code and little to no proper documentation. Things like calling their custom functions, for example:

include a \
b \
c

— Are syntactically just unappealing. We all know many things aren't supported in pure bash and therefore probably shouldn't be extended by using bash. Bash is not written in bash, it's written in C. Why are these so called custom libararies not written in C to properly extend bash? Better yet, why not attempt to include it in the source itself?

Saving 'boilerplate' code is one thing, but these attempts usually go way past that by trying to make things possible that shouldn't be, like interfaces and types for example. I wrote my own in the past without intention to extend bash itself but make it's current capabilities a bit simpler. Still I never use it myself

Maybe people don't realize they could be contributing to a bigger picture by extending bash source itself, so the wheel ends up reinvented endlessly

Curious what everyone things about these custom modules/frameworks/libraries that are available and if people really use them in every (most) project(s) they write. Let me know what you think..

https://redd.it/146rm8m
@r_bash
Need help with quoting a command that already has quotes.

I am currently editing .twmrc file. In the menu, I want one of the entry to launch j4-dmenu-desktop, which launches dmenu.
Back when I was using i3wm, the (related) configuration is:

set $fc #AAAAAA
set $bc #000000
set $fnt pango:Pragmata Pro Mono 7
bindsym $mod+e exec --no-startup-id i3-dmenu-desktop --dmenu="dmenu -i -fn Pragmata\ Pro\ Mono-7 -nb \$bc -nf \$fc -sb \$fc -sf \$bc" --entry-type=name
Now I have switched to TWM; since the built-in application menu does not list all applications, I removed the entries and added one for dmenu (the "Prg List" one):

menu "main"
{
"Terminal" f.exec "urxvtc"
"Prg List" f.exec "j4-dmenu-desktop --dmenu=\"dmenu -i\" &"
"Icon Mgr" f.showiconmgr
"Exit GUI" f.quit
}
The above menu is working, but I want dmenu to appear the same (the font and colours). The problem is that the font name has spaces, the colour has a "#", and I have to quote something that is already in quotes.

https://redd.it/146wjf8
@r_bash
How to interject dates into a list of existing dates and adopt previous value

Hi All,

Apologies for the poorly described noscript but Im unsure how to describe this request.

Basically I have a file similar to the below.

12/06/2023,100
11/06/2023,106
09/06/2023,110
08/06/2023,90
05/06/2023,95
04/06/2023,110

I was hoping that there would be a bash command that could insert the missing dates and adopt the previous assigned value. Similar to the following:

12/06/2023,100
11/06/2023,106
10/06/2023,110 >> New line adopting 110 from 09/06/2023
09/06/2023,110
08/06/2023,90
07/06/2023,95 >> New line adopting 95 from 06/06/2023
06/06/2023,95 >> New line adopting 95 from 05/06/2023
05/06/2023,95
04/06/2023,110

Can anyone think of a method to achieve this?

Thanks

https://redd.it/14754ia
@r_bash
grep says "argument list too long" in a bash noscript, but, not in a terminal.

So, in a particular bash noscript, I run curl and get a really long single-line output that I need to run `grep` on.

Except, I get a "argument list too long" error.

But, if I just ssh into this machine and run the same commands in the terminal without using the noscript, I don't get this "argument list too long" error.

So, how do I get around this?

> ./noscript_name.sh: line 232: /usr/bin/grep: Argument list too long

https://redd.it/1476xf2
@r_bash
How Do I include a the header using awk?

Here's my code: grep -i -e "Ready to Open" Operation_boxes.csv | awk -F, $16 >= 7 {print}' after command is executed it only displays the values under the headers in the CSV file. Even when adding NR=1, it doesn't seem to work and I can't wrap my head around why. If you need more information please ask, I am a beginner and would really appreciate the help :)

https://redd.it/1478zjg
@r_bash