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
Point me in the right direction, please - writing a bash function involving a user prompt
So I'm trying to make a function that creates the directory structure for ansible roles, example command that works standalone, below:
mkdir -p RoleName/{tasks,handlers,defaults,vars,templates}
I've only really done basic work in bash, so I'm a bit lost.
I initially tried to setup an alias, init-role, to run the above using "read -p" to get the folder name, but that didn't quite work. After searching around online, it seems a function is what I want. Here is a list of commands that work, and would probably work if I threw them into a noscript:
# ask for the name of the role
read -p 'Enter the role name: ' RoleName
# use RoleName as the root folder, and make the subfolders
mkdir -p $RoleName/{tasks,handlers,defaults,vars,templates}
# Remove the alias
unset $RoleName
# Show the directory structure
tree
After configuring my \~/.bashrc to look at \~/.bash_functions, and threw the above into a function, I quickly learned it wasn't correct. This is what I have:
function init-role () {
# ask for the name of the role
read -p 'Enter the role name: ' RoleName
# use RoleName as the root folder, and make the subfolders
mkdir -p $RoleName/{tasks,handlers,defaults,vars,templates}
# Remove the alias
unset $RoleName
# Show the directory structure
tree
}
Right now I'm stuck on getting user input and putting it into a variable. I've tried:
$RoleName = read -p 'Enter the role name: '
$RoleName = read -p "Enter the role name: "
$RoleName = "read -p Enter the role name: "
My search queries aren't getting me anywhere regarding getting user input, and assigning it to a variable, within a function. I'm sure it's out there, I'm just not finding it.
​
It's probably clear that I haven't written a bash function before, and I'm not really looking for an answer to be handed to me, but rather a pointer in the right direction, please.
https://redd.it/14mszdj
@r_bash
So I'm trying to make a function that creates the directory structure for ansible roles, example command that works standalone, below:
mkdir -p RoleName/{tasks,handlers,defaults,vars,templates}
I've only really done basic work in bash, so I'm a bit lost.
I initially tried to setup an alias, init-role, to run the above using "read -p" to get the folder name, but that didn't quite work. After searching around online, it seems a function is what I want. Here is a list of commands that work, and would probably work if I threw them into a noscript:
# ask for the name of the role
read -p 'Enter the role name: ' RoleName
# use RoleName as the root folder, and make the subfolders
mkdir -p $RoleName/{tasks,handlers,defaults,vars,templates}
# Remove the alias
unset $RoleName
# Show the directory structure
tree
After configuring my \~/.bashrc to look at \~/.bash_functions, and threw the above into a function, I quickly learned it wasn't correct. This is what I have:
function init-role () {
# ask for the name of the role
read -p 'Enter the role name: ' RoleName
# use RoleName as the root folder, and make the subfolders
mkdir -p $RoleName/{tasks,handlers,defaults,vars,templates}
# Remove the alias
unset $RoleName
# Show the directory structure
tree
}
Right now I'm stuck on getting user input and putting it into a variable. I've tried:
$RoleName = read -p 'Enter the role name: '
$RoleName = read -p "Enter the role name: "
$RoleName = "read -p Enter the role name: "
My search queries aren't getting me anywhere regarding getting user input, and assigning it to a variable, within a function. I'm sure it's out there, I'm just not finding it.
​
It's probably clear that I haven't written a bash function before, and I'm not really looking for an answer to be handed to me, but rather a pointer in the right direction, please.
https://redd.it/14mszdj
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How can I add this functionality to my Bash?
In this video the presenter installs zsh and is able to type
https://redd.it/14v7kqm
@r_bash
In this video the presenter installs zsh and is able to type
git st, then use the tab key to bring up a list of commands that start with git st (stash, status, stripspace) and brief denoscriptions of each. Is there a way to do this with Bash?https://redd.it/14v7kqm
@r_bash
YouTube
My development environment | From scratch | Ubuntu | 2020
Setting up my Linux development environment from scratch in Ubuntu.
⏱️TIMESTAMPS⏱️
0:00 - My development environment - From scratch - Ubuntu
0:07 - Start of the video
0:50 - Terminals
0:51 - Terminator
2:16 - Alacritty
3:12 - Fundamental tools installation…
⏱️TIMESTAMPS⏱️
0:00 - My development environment - From scratch - Ubuntu
0:07 - Start of the video
0:50 - Terminals
0:51 - Terminator
2:16 - Alacritty
3:12 - Fundamental tools installation…