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
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
Reddit
r/bash on Reddit: Using select with command output
Posted by u/go_comatose_for_me - No votes and 1 comment
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
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
Reddit
r/bash on Reddit: What does the second line do?
Posted by u/s1eve_mcdichae1 - No votes and no comments
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
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
Reddit
r/bash on Reddit: Need help using a text file as input for case selection.
Posted by u/RedHeadHippy666 - No votes and 2 comments
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
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
Reddit
From the ModCoord community on Reddit
Explore this post and more from the ModCoord community
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
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
Reddit
r/bash on Reddit: Need help with a noscript
Posted by u/Logunstious - No votes and 2 comments
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
https://redd.it/146abdr
@r_bash
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
Reddit
r/bash on Reddit: Running weekly average
Posted by u/go_comatose_for_me - No votes and no comments
My bash module framework now supports interfaces and inheritance
https://m10k.eu/2023/06/10/toolbox-interfaces.html
https://redd.it/146mgxn
@r_bash
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:
— 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
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
Reddit
r/bash on Reddit: Modules, frameworks, libararies
Posted by u/wick3dr0se - No votes and 1 comment
Need help with quoting a command that already has quotes.
I am currently editing
Back when I was using
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
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
https://redd.it/146wjf8
@r_bash
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
Reddit
r/bash on Reddit: Need help with quoting a command that already has quotes.
Posted by u/pthfdr - No votes and no comments
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
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
Reddit
r/bash on Reddit: How to interject dates into a list of existing dates and adopt previous value
Posted by u/9mHoq7ar4Z - No votes and no comments
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
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
Reddit
r/bash on Reddit: grep says "argument list too long" in a bash noscript, but, not in a terminal.
Posted by u/stop_lying_good_god - No votes and no comments
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
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
Reddit
r/bash on Reddit: How Do I include a the header using awk?
Posted by u/dennisysj - No votes and no comments
/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
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
OK We are open again
OK As a mod team we seem to be unable to reach a decision what to do next, so I have decided to seek forgiveness rather than permission.
The sub is now public again and I have stood down as a moderator.
I'll still be around as a poster but someone other than me can take the decision to close the sub if that is what they want.
https://redd.it/14eh7xb
@r_bash
OK As a mod team we seem to be unable to reach a decision what to do next, so I have decided to seek forgiveness rather than permission.
The sub is now public again and I have stood down as a moderator.
I'll still be around as a poster but someone other than me can take the decision to close the sub if that is what they want.
https://redd.it/14eh7xb
@r_bash
Reddit
r/bash on Reddit: OK We are open again
Posted by u/Electronic_Youth - 26 votes and 23 comments
run Linux command and save output as variable?
Fairly new to bash noscripts and want some help.
​
I want to have my bash noscript run a command to find the PC architecture, like run "uname -a" and see that the PC is either amd64 or ARM and based on the architecture run certain commands. I know how to execute the loop, but where I'm having difficulty is saving the command output as a variable.
​
How would we use a bash noscript to save the output as a variable?
https://redd.it/14flv3u
@r_bash
Fairly new to bash noscripts and want some help.
​
I want to have my bash noscript run a command to find the PC architecture, like run "uname -a" and see that the PC is either amd64 or ARM and based on the architecture run certain commands. I know how to execute the loop, but where I'm having difficulty is saving the command output as a variable.
​
How would we use a bash noscript to save the output as a variable?
https://redd.it/14flv3u
@r_bash
Reddit
r/bash on Reddit: run Linux command and save output as variable?
Posted by u/CommercialEnd7514 - No votes and 3 comments
changing text output on CLI
Hi.
I was trying to figure this out.
I'm in this directory:
I want to get pwd --> s/3U/4U/ --> input to
I tried various permutations of
https://redd.it/14fcu1a
@r_bash
Hi.
I was trying to figure this out.
I'm in this directory:
/mnt/myData/Teach/course_websites/ICS3U1/exam/review and want to change to the same directory, but with 4U instead of 3U. The text is output from pwd.I want to get pwd --> s/3U/4U/ --> input to
cd commmand.I tried various permutations of
cd $(pwd|& ^3U^4U) and cd $(pwd |& {"/3U/4U"} but I don't know enough to get it working.https://redd.it/14fcu1a
@r_bash
Reddit
r/bash on Reddit: changing text output on CLI
Posted by u/mk_gecko - 4 votes and 6 comments
Is it normal for bash to be extremely difficult or is it just me
Is it normal for people to find bash extremely difficult to learn even though you have basic coding background in other languages(java, python, js) or is it just me and should move on to something else.
https://redd.it/14fna38
@r_bash
Is it normal for people to find bash extremely difficult to learn even though you have basic coding background in other languages(java, python, js) or is it just me and should move on to something else.
https://redd.it/14fna38
@r_bash
Reddit
r/bash on Reddit: Is it normal for bash to be extremely difficult or is it just me
Posted by u/dennisysj - 2 votes and 3 comments
How can I pass a variable to jq in a loop
I am trying to create a loop to create a new object but it seems like "something name": ~~$line~~ throws an error as jq is not able to handle $line in that format. Any clue to how I should wrap it?
bonus: jq also always adds an empty value to my members array. Any clue how to remove it? The input is a line separated list
​
az ad group list --filter "startswith(displayName,'something')" --query ".displayName" -o tsv | \
while read line; \
do az ad group member list \
--group $line \
--query ".mail" -o tsv | \
jq -Rs 'split("\n") | \
{"something name": $line, "members": .}' ; \
done
​
https://redd.it/14flxcg
@r_bash
I am trying to create a loop to create a new object but it seems like "something name": ~~$line~~ throws an error as jq is not able to handle $line in that format. Any clue to how I should wrap it?
bonus: jq also always adds an empty value to my members array. Any clue how to remove it? The input is a line separated list
​
az ad group list --filter "startswith(displayName,'something')" --query ".displayName" -o tsv | \
while read line; \
do az ad group member list \
--group $line \
--query ".mail" -o tsv | \
jq -Rs 'split("\n") | \
{"something name": $line, "members": .}' ; \
done
​
https://redd.it/14flxcg
@r_bash
Reddit
r/bash on Reddit: How can I pass a variable to jq in a loop
Posted by u/blackfalconx - No votes and 2 comments
Whitespace password generator
#!/bin/bash
# Generate a purely whitespace password with 128 bits of symmetric security.
#
# Characters are strictly non-control, non-graphical spaces/blanks. Both
# nonzero- and zero-width characters are used. Two characters are technically
# vertical characters, but aren't interpreted as such in the shell. They are
# "\u2028" and "\u2029". You might need a font with good Unicode support to
# prevent some of these characters creating tofu.
rng() {
# Cryptographically secure RNG
local min=$((2 32 % 30)) # 30 = size of $s below
local r=$SRANDOM
while "$r" -lt "$min" ; do r=$SRANDOM; done # Modulo with rejection
echo "$(($r % 30))"
}
s=(
# Non-zero width characters
"\u0009" # Character tabulation
"\u0020" # Space
"\u00A0" # Non-breaking space
"\u2000" # En quad
"\u2001" # Em quad
"\u2002" # En space
"\u2003" # Em space
"\u2004" # Three-per-em space
"\u2005" # Four-per-em space
"\u2006" # Six-per-em space
"\u2007" # Figure space
"\u2008" # Punctuation space
"\u2009" # Thin space
"\u200A" # Hair space
"\u2028" # Line separator
"\u2029" # Paragraph separator
"\u202F" # Narrow no-break space
"\u205F" # Medium mathematical space
"\u2800" # Braille pattern blank
"\u3000" # Ideographic space
"\u3164" # Hangul filler
"\uFFA0" # Halfwidth hangul filler
# Zero width characters
"\u115F" # Hangul choseong filler
"\u1160" # Hangul jungseong filler
"\u180E" # Mongolian vowel separator
"\u200B" # Zero width space
"\u200C" # Zero width non-joiner
"\u200D" # Zero width joiner
"\u2060" # Word joiner
"\uFEFF" # Zero width non-breaking space
)
p=""
# Generate 27 characters for at least 128 bits security
for i in {1..27}; do
r=$(rng)
c=${s$r}
p="${p}${c}"
done
tabs -1 # Tab width of 1 space
# Wrap the password in braille pattern blanks for correctly handling zero-width
# characters at the edges and to prevent whitespace stripping by the auth form.
echo -e "\"\u2800${p}\u2800\""
Example:
$ bash /tmp/whitespace.bash
"⠀ ⠀ ᅠᅠᅠㅤ ⠀ ⠀"
https://redd.it/14hfrou
@r_bash
#!/bin/bash
# Generate a purely whitespace password with 128 bits of symmetric security.
#
# Characters are strictly non-control, non-graphical spaces/blanks. Both
# nonzero- and zero-width characters are used. Two characters are technically
# vertical characters, but aren't interpreted as such in the shell. They are
# "\u2028" and "\u2029". You might need a font with good Unicode support to
# prevent some of these characters creating tofu.
rng() {
# Cryptographically secure RNG
local min=$((2 32 % 30)) # 30 = size of $s below
local r=$SRANDOM
while "$r" -lt "$min" ; do r=$SRANDOM; done # Modulo with rejection
echo "$(($r % 30))"
}
s=(
# Non-zero width characters
"\u0009" # Character tabulation
"\u0020" # Space
"\u00A0" # Non-breaking space
"\u2000" # En quad
"\u2001" # Em quad
"\u2002" # En space
"\u2003" # Em space
"\u2004" # Three-per-em space
"\u2005" # Four-per-em space
"\u2006" # Six-per-em space
"\u2007" # Figure space
"\u2008" # Punctuation space
"\u2009" # Thin space
"\u200A" # Hair space
"\u2028" # Line separator
"\u2029" # Paragraph separator
"\u202F" # Narrow no-break space
"\u205F" # Medium mathematical space
"\u2800" # Braille pattern blank
"\u3000" # Ideographic space
"\u3164" # Hangul filler
"\uFFA0" # Halfwidth hangul filler
# Zero width characters
"\u115F" # Hangul choseong filler
"\u1160" # Hangul jungseong filler
"\u180E" # Mongolian vowel separator
"\u200B" # Zero width space
"\u200C" # Zero width non-joiner
"\u200D" # Zero width joiner
"\u2060" # Word joiner
"\uFEFF" # Zero width non-breaking space
)
p=""
# Generate 27 characters for at least 128 bits security
for i in {1..27}; do
r=$(rng)
c=${s$r}
p="${p}${c}"
done
tabs -1 # Tab width of 1 space
# Wrap the password in braille pattern blanks for correctly handling zero-width
# characters at the edges and to prevent whitespace stripping by the auth form.
echo -e "\"\u2800${p}\u2800\""
Example:
$ bash /tmp/whitespace.bash
"⠀ ⠀ ᅠᅠᅠㅤ ⠀ ⠀"
https://redd.it/14hfrou
@r_bash
Reddit
r/bash on Reddit: Whitespace password generator
Posted by u/atoponce - 6 votes and 4 comments
What is the "-" called and what is it exactly doing?
hey bashers,
tar -cvzf - some.file | split -b 150M - "some.file-part"
I know what this line does, but I do not really understand the " - " and i don't know how this concept is called. Does this have a name? "Buffer into Terminal"?
​
Best
​
https://redd.it/14jevh3
@r_bash
hey bashers,
tar -cvzf - some.file | split -b 150M - "some.file-part"
I know what this line does, but I do not really understand the " - " and i don't know how this concept is called. Does this have a name? "Buffer into Terminal"?
​
Best
​
https://redd.it/14jevh3
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Keep a Mac awake for any duration with a user friendly easy to setup noscript that uses the native MacOS pmset disablesleep
Hey all,
​
I often need to prevent a Mac from sleeping and Caffeinate & Amphetamine are neither open source not work very well so I created a light user friendly Bash noscript with more advanced options.
​
You can keep your Mac awake indefinitely or for any duration you set. It also works when a MacBook lid is closed and to cancel a sleep you simply press the return key. Can't be easier than that..
​
You can specify a wake duration in seconds, minutes, or hours, and it can even handle multiple arguments at the same time. (e.g. by running ```./stay-awake 1h 30m 15s```)
​
Check out the open-source repository at - [https://github.com/Post2Fix/macos-stay-awake\](https://github.com/Post2Fix/macos-stay-awake)
​
There are simple instructions on how to setup and run a Bash noscript on MacOS which can be handy to know anyway.
​
I'll try to turn it into an executable MacOS app for everyone but until then hopefully some early adopters will find it useful. Let me know if you have any suggestions or issues.
​
Best.
https://redd.it/14mmksd
@r_bash
Hey all,
​
I often need to prevent a Mac from sleeping and Caffeinate & Amphetamine are neither open source not work very well so I created a light user friendly Bash noscript with more advanced options.
​
You can keep your Mac awake indefinitely or for any duration you set. It also works when a MacBook lid is closed and to cancel a sleep you simply press the return key. Can't be easier than that..
​
You can specify a wake duration in seconds, minutes, or hours, and it can even handle multiple arguments at the same time. (e.g. by running ```./stay-awake 1h 30m 15s```)
​
Check out the open-source repository at - [https://github.com/Post2Fix/macos-stay-awake\](https://github.com/Post2Fix/macos-stay-awake)
​
There are simple instructions on how to setup and run a Bash noscript on MacOS which can be handy to know anyway.
​
I'll try to turn it into an executable MacOS app for everyone but until then hopefully some early adopters will find it useful. Let me know if you have any suggestions or issues.
​
Best.
https://redd.it/14mmksd
@r_bash
GitHub
GitHub - Post2Fix/macos-stay-awake: Easily executable noscript file to prevent MacOS sleep for a specified duration
Easily executable noscript file to prevent MacOS sleep for a specified duration - GitHub - Post2Fix/macos-stay-awake: Easily executable noscript file to prevent MacOS sleep for a specified duration