/r/bash Blackout Community Vote
Hello /r/bash. Your mods have been discussing the future of the subreddit in light of recent developments, and we've decided to bring this to the community for discussion and a vote. We highly encourage reading /r/philosophy's excellent post to understand why API access matters.
There are three options which control the ability of users to post and view on a subreddit.
- Public: Anyone can view, post, and comment to this community
- Restricted: Anyone can view this community, but only approved users can post: (We would use this to basically set /r/bash to "read-only")
- Private: Only approved users can view and submit to this community
Please upvote or downvote the comments below to express your opinion on the matter. If there are other reasons for taking a particular stance, please add a comment under the relevant top-level comment.
https://redd.it/14bodru
@r_bash
grep says "argument list too long" in a bash script, but, not in a terminal.
So, in a particular bash script, 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 script, I don't get this "argument list too long" error.
So, how do I get around this?
> ./script_name.sh: line 232: /usr/bin/grep: Argument list too long
https://redd.it/1476xf2
@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
My bash module framework now supports interfaces and inheritance
https://m10k.eu/2023/06/10/toolbox-interfaces.html
https://redd.it/146mgxn
@r_bash
Need help with a script
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
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
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
10 Unix File Management Commands That Every Developer Should Know
https://levelup.gitconnected.com/10-unix-file-management-commands-that-every-developer-should-know-afc6bdc4f27c?sk=be6fd6d1dc6cd2b32ec07bdebdf260e4
https://redd.it/1446ekg
@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
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'
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 scripts 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
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
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 scripts 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 scripting. 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 script 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 scripts functionality. With my script 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
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
printf not completely converted
numbers="50 75"
thistime=$(( $(date +%s)+$(printf '%d' "$numbers" | awk '{print $1}') ))
printf: 50 75: not completely converted
​
thisTime should be equal to the current time in seconds (since 1970) + 50
https://redd.it/141ly34
@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
How to interject dates into a list of existing dates and adopt previous value
Hi All,
Apologies for the poorly described title 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
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
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
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
What does the second line do?
scriptdir="$(dirname "$0")"
scriptdir="$(cd "$scriptdir" && pwd)"
First line sets the variable to the directory the script 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
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
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 script 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
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;
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
Add timestamp to stderr redirect
I'm running a script 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 script 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
My bash script work manually, but in crontab does not work
I have this shell script
#!/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 $userendpoints
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 $serviceendpoints
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 script 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
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
#!/usr/bin/bash -eu
Can someone explain what the -eu means in this example please?
I see it mostly at the beginning of shell scripts, etc.
Thanks.
https://redd.it/141ry2f
@r_bash
npid - Get name of process by pid
https://github.com/thingsiplay/npid
https://redd.it/141fs84
@r_bash