r_bash – Telegram
How to interject dates into a list of existing dates and adopt previous value

Hi All,

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

Basically I have a file similar to the below.

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

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

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

Can anyone think of a method to achieve this?

Thanks

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

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

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

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

So, how do I get around this?

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

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

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

https://redd.it/1478zjg
@r_bash
/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
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
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
changing text output on CLI

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
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
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
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
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
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
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
How can I add this functionality to my 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
Execute a command in every sub-directory that contains wav files.

# Problem is solved! Thank you all for Helping! See comments for solution.

Hey there,

I have a collection of Drum Staples for Producing Music. The are Organized in different Folder for every Drum-Machine. In most sub-directories the samples are located directly in this folder. In some directories there are sub-folders for the different sounds (bass drum, snare, hats...).

I need a noscript or command that executes "normalize-audio -b \*.wav" in every sub-directory.

Searching the Web, I found this:

find ./* -type d -execdir echo Doing something in folder {} \; -execdir echo Done something in {} \;

It works well and executes the Echo command in every Sub. So i Changed it to

find ./* -type d -execdir normalize-audio -b {}/*.wav;

I tried it without the {} and put the Normalize Command in ' , But it just gives me error messages, mostly this one:

find: missing argument to `-execdir'

I've been tinkering with this command for 3 hours. Now it's time to admit that this is above my level and ask the community for advice.

Greetings from Germany!

https://redd.it/14v4rtw
@r_bash
A universal noscript to open Firefox with piped search terms in Bash

#!/bin/bash
set -e
shopt -s lastpipe
read -r input;

getos () {
uname
s="$(uname -s)"
if echo "$unames" | grep 'Darwin' >/dev/null
then
baseos='osx'
else
if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then
baseos='windows'
else
baseos='linux'
fi
fi
echo $baseos
}

set
firefoxpath () {
if [ "$(get
os)" == "windows" ]; then
export FIREFOXBIN="/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
elif [ "$(get
os)" == "linux" ]; then
export FIREFOXBIN="firefox"
elif [ "$(get
os)" == "osx" ]; then
export FIREFOXBIN="/Applications/Firefox.app/Contents/MacOS/firefox"
else
echo "Unknown OS"
exit 1
fi
}

google () {
TLD=".
co.uk"
search=""
for term in "$@"; do
search="${search}%20${term}"
done
"${FIREFOX
BIN}" "https://www.google${TLD}/search?q=${search}" &
}

setfirefoxpath
google "${input}"

https://redd.it/14uosqq
@r_bash
Better way to get variables out of file

I have two files:

#config
nextcloud-1="/var/www/nextcloud-1"
nextcloud-2="/var/www/nextcloud-2"

and the actual noscript:

#!/bin/bash
dir="$1"
dir=$(cat /opt/dirs.txt | grep "$dir" | sed -e 's/.*"\(.*\)".*/\1/')
cd $dir
sudo -u www-data php -f occ app:update --all

This noscript updates all Nextcloud apps on the selected instance: `./updateapps.sh nextcloud-1`. Is there a more efficient way of doing this, with error handling in case of a non-existent directory/variable for directory?

https://redd.it/14tzjik
@r_bash
Help me

So i got this problem as summer homework:Write a bash noscript that prompts the user to enter an upper limit. The program will calculate the sum of all prime numbers between 2 and the specified limit. Next, the program will have to generate a text file called "primes.txt" that will contain the prime numbers found, one per line. This is what i wrote:

#!/bin/bash
# Function that checks if a number is prime
function is_prime() {
if (( $1 < 2 )); then
return 1
fi
for (( i=2; i*i<=$1; i++ )); do
if (( $1 % $i == 0 )); then
return 1
fi
done
return 0
}
# Function that calculates the sum of prime numbers up to a given limit
function calculate_prime_sum() {
local limit=$1
local sum=0
for (( num=2; num<=limit; num++ )); do
if is_prime $num; then
      (( sum += num ))
fi
done
echo $sum
}
# Read a number from input
read -p "Enter an upper limit: " limit
# Calculate the sum of prime numbers up to the limit
prime_sum=$(calculate_prime_sum $limit)
echo "The sum of prime numbers up to $limit is $prime_sum"
# Generate a text file with prime numbers up to the limit
echo "Prime numbers up to $limit:" > primes.txt
for (( num=2; num<=limit; num++ )); do
if is_prime $num; then
echo $num >> primes.txt
fi
done
echo "primes.txt file generated successfully."
I dont know why but it gives an error :( can someone help me?

https://redd.it/14u6cfy
@r_bash