r_bash – Telegram
these lines causing errors but I swear they weren't causing error before and I didn't change anything

i=0
while read l
do
varr=$(printf "$l" | awk --field-separator="|" "{ print NF }" )
"$varr" -eq 2 || "$varr" -eq 4 || i=$((i+2))

done < file

the error is this

[: Illegal number:

https://redd.it/140q88d
@r_bash
Dispatcher does nothing on my machine?

I am using this commonly known noscript which isn't working for me at all. As in, no output and no changes in WiFi status:

&#x200B;

#!/bin/bash

enabledisablewifi ()
{
result=$(nmcli dev | grep "ethernet" | grep -w "connected")
if -n "$result" ; then
nmcli radio wifi off
# echo "off"
else
nmcli radio wifi on
# echo "on"
fi
}

if "$2" = "up" ; then
enabledisablewifi
fi

if "$2" = "down" ; then
enabledisablewifi
fi

This is my output of "nmcli dev | grep "ethernet" | grep -w "connected"

enp52s0f3u1u3u4 ethernet connected My Ethernet

What am I doing wrong? :o

https://redd.it/1414kpb
@r_bash
printf not completely converted

numbers="50 75"

thistime=$(( $(date +%s)+$(printf '%d' "$numbers" | awk '{print $1}') ))

printf: 50 75: not completely converted

&#x200B;

thisTime should be equal to the current time in seconds (since 1970) + 50

https://redd.it/141ly34
@r_bash
#!/usr/bin/bash -eu

Can someone explain what the -eu means in this example please?

I see it mostly at the beginning of shell noscripts, etc.

Thanks.

https://redd.it/141ry2f
@r_bash
awk just printing what I want it to append in the console instead of actually appending it

awk -v mynum="$(mynumber)" -F ',' 'NF==2{print $0" , -5 , mynum , 3 "}' file

so if there is one comma on a line, it should turn

a ,b

to

a , b , -5, mynum , 3

I don't understand why this doesn't work

https://redd.it/141xsra
@r_bash
Terminal acts sporadic at times

If I run a command $ while ! ping -c 1 -W 1 1.1.1.1; do echo "still waiting for 1.1.1.1" sleep 1 done and I recall it with the up arrow or I recopy and paste it, the order of the command comes up in a weird order and there is no dollar sign preceding the command like such still waiting for 1.1.1.1" sleep 1 done while ! ping -c 1 -W 1 1.1.1.1; do echo ". Also when I press backspace, it clears what I inputted but then it continues to clear what I've entered previously in "history", the backspace doesn't stop at the end of the line, it continues onto the previous lines (as if the screen is a giant txt file). I've had this issue come up in git bash as well. When I reopen my terminal this issue is resolved. It seems like a common issue and I've entered some sort of mode but I don't know how to fix it besides restarting the terminal. Any help would be appreciated.

https://redd.it/141xccx
@r_bash
I made a better bashmarks

So, I was trying to find a good directory bookmarking utility for terminal use, so I can cd faster and also build other noscripts around it too. I didn't find anything satisfactory. The closest thing was bashmarks, but I didn't like the way it was written and it worked. It already had done a lot of the groundwork for me and it was a good basis to start, so I decided to fork it and work from there.

And that's what I did. I also decided to make it POSIX compliant so it works with /bin/sh and dash for speed or whatever. Took me a few hours as I'm not great at shell noscripting. If anyone wants to check it out, here's the github repo.

In my opinion, which is correct, it is better than bashmarks because it doesn't hijack the possible one character aliases one might personally want to make, it also doesn't require the user to source the noscript in their bash or zsh config, and it doesn't work using environment variables like bashmarks does. It's easy to combine with a program like dmenu or fzf to choose from the list of available bookmarks as well. It also does thorough error checking, and extends the noscripts functionality. With my noscript you are able to print or delete multiple bookmarks at once, and set a new bookmark using the current working directory, or pass one as an argument.

Anyway, if you want to try a faster way to travel between commonly CDed dirs, then give it a try.

https://redd.it/142460x
@r_bash
My bash noscript work manually, but in crontab does not work

I have this shell noscript

#!/bin/bash

userendpoints=`cat user.log |cut -d '|' -f5|jq '.request.address'|sed -e 's|upload|\nupload|g'|grep -v upload|sort |uniq`


IFS=$'\n'

echo "endpoint|count|type of response"
for i in $user
endpoints
do
data=cat user.log|grep "$i"|cut -d '|' -f5|jq '.response.status'|sort|uniq -c|sed -e 's/$/|/g' -e 's/ //g' -e 's/^ //g'
for d in echo $data|tr '|' '\n'
do
echo "$i" "|" echo $d|sed -e 's/^ //'|tr -s ' ' '|'
done
done



serviceendpoints=` cat service.log |cut -d '|' -f5|jq '.request.address'|sed -e 's|compare|compare\n trunk|g' -e 's|livenessCheck|livenessCheck\n trunk|g'|grep -v trunk|sort |uniq`


for i in $service
endpoints
do
data=cat service.log|grep "$i"|cut -d '|' -f5|jq '.response.status'|sort|uniq -c|sed -e 's/$/|/g' -e 's/ //g' -e 's/^ //g'
for d in echo $data|tr '|' '\n'
do
echo "$i" "|" echo $d|sed -e 's/^ //'|tr -s ' ' '|'
done
done


when I run this shell noscript manually it work and give me result, but when I put it in crontab I see this error and does not give us result and I see this error


cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: user.log: No such file or directory
cat: service.log: No such file or directory
cat: service.log: No such file or directory
cat: service.log: No such file or directory
cat: service.log: No such file or directory
cat: service.log: No such file or directory

I use oracle Linux.

https://redd.it/1429m19
@r_bash
This media is not supported in your browser
VIEW IN TELEGRAM
I have developed my own Appimage package manager in full BASH, here are 3 different approuches to install the apps: xterm (1, the default one, allows to interact when prompted questions), less (2, clean but non interactive) or nothing (not clean). What is better? Have you got suggestions?

https://redd.it/142d9nx
@r_bash
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