r_bash – Telegram
"echo hello > /dev/stdout | echo world" does't make sense

Hello everyone I'm trying to understand this command behaviour, I'm remaking a shell for a school project and bash --posix behaviour looks weird to me.

Why does this command only print "world" ?
My understanding is that bash create the pipe, close it and redirect the first command STDOUT to /dev/stdout so why won't it print "hello" on the terminal ?

https://redd.it/z02289
@r_bash
Grep a*b

Hello
How can I use grep to show only line that have a*b and a*c and a*d ( the à is repeated in all strings, the * can be anything and the C is the value that I'mlooking for).

Thanks

https://redd.it/z03wyn
@r_bash
extract key and value from log

I try extract key and value from but I can’t do it:

2022-11-20 11:52:20 - Processing ProtocolSpec: {'status': 'SENDERR:FileSender.sendFile:ProtocolException("error(111, \\'Connection refused\\')[Errno 111\] Connection refused",)error(111, \\'Connection refused\\')[Errno 111\] Connection refused', 'datamode': 'att', 'contenttype': 'html', 'warnings': 'Malformed cco email address: . Malformed cco email address: . ', 'datatype': 'bin', 'backup': '1', 'from_addr': 'mail@mail', 'to_addr': [u'user@mail'\], 'filename': 'XX.00XX.XXX.X.000000.CMAS.zip', 'actions': [u'zip'\], 'ser_key': 'protocol', 'content': 'File Attached.<BR><BR>Report', 'cco_addr': [u''\], 'fid': '20149431.00', 'alert_done': 0, 'type': 'mailbody', 'onemptydata': 'process', 'subject': 'TID FILE'}

i need extract this 'filename': 'XX.00XX.XXX.X.000000.CMAS.zip'

any helps?

regards,

https://redd.it/z062mx
@r_bash
BashLib a helpful source file for any noscript

This is something I made awhile back. Its extremely useful for making games, if youre into that, but it is good for just about anything really. Im open to suggestions.

https://github.com/DethByte64/BashLib

https://redd.it/z09oiu
@r_bash
Displaying datas in an array

Hello,

I'm trying to draw an array for displaying datas. I succeeded for the first row with as many columns I want, but I have a trouble to draw the others rows. I think there is an easy way to do it. Could you help me ?

drawarray()
`{`

`border=("╔" "═" "╗" "║" "╚" "╝" "╠" "╩" "╦" "╣" "╬")`

`pos
x=$1 ; posy=$2 ; borderbg=$3 ; borderclr=$4 ; nbcols=$5 ; nbrows=$6`

`shift 6`

`columns=1 ; rows=1 ; height=1 ; array
rows=1

tput setab $borderbg ; tput setaf $borderclr ; tput cup $posy $posx

leftup=${border[0]} ; midup=${border8} ; rightup=${border[2]} ; hor=${border[1]} ; ver=${border[3]}`

`left
mid=${border0} ; midmid=${border[8]} ; rightmid=${border2}

printf "%s" $leftup`

`for loop
columns in `seq 1 $nbcols\``

`do`

`width
cell$loop_columns=$1 ; heightcell=$2`

`for loop in \`seq 1 ${width
cell$loop_columns}` ; do printf "%s" $hor ; done

if [ $columns -lt $nb_cols ] ; then
printf "%s" $mid_up
elif [ $columns -gt 1 ] && [ $columns -lt $nb_cols ] ; then
printf "%s" $mid_up
elif [ $columns -eq $nb_cols ] ; then
printf "%s\n" $right_up
fi

((columns++))

shift

done

while [ $height -lt $((height_cell+1)) ]

do
tput cup $((pos_y+height)) $pos_x
printf "%s\n" $ver
pos_x2=$pos_x
for loop_columns in \seq 1 $nb_cols

do
pos_x=$((pos_x+width_cell[$loop_columns]))
for loop in \seq 1 ${width_cell[$loop_columns]}
; do tput cup $((posy+height)) $((posx+$loopcolumns)) ; done`
if [[ $cols -lt $nb
columns ]] || [ $cols -gt 1 ] && [ $cols -lt $nb_columns ] || [ $cols -eq $nb_columns ] ; then
printf "%s\n" $ver
fi
done
((height++))
if [ $loop_columns -eq $nb_cols ] ; then posx=$posx2 ; fi
done

if [[ $rows -eq $nb_rows ]] ; then

left_down=${border[4]} ; mid_down=${border[7]} ; right_down=${border[5]}

elif [[ $rows -lt $nb_rows ]] ; then

left_down=${border[6]} ; mid_down=${border[10]} ; right_down=${border[9]}

fi

tput cup $((pos_y+height)) $pos_x

printf "%s" $left_down

cols=1

for loop_columns in \seq 1 $nbcols\``

`do`
for loop in \seq 1 ${width
cell$loop_columns} ; do printf "%s" $hor ; done
if [ $cols -lt $nb_cols ] ; then
printf "%s" $middown
elif [[ $cols -gt 1 ]] && [[ $cols -lt $nb
cols ]] ; then
printf "%s" $middown
elif [[ $cols -eq $nb
cols ]] ; then
printf "%s\n" $rightdown
fi
((cols++))
`done`

`echo`

`echo`

`tput sgr 0`

`}`


and here the command to call it :

draw
array 10 12 0 7 4 3 20 15 10 5 3 20 15 10 5 3

&#x200B;

and the result :












╔════════════════════╦═══════════════╦══════════╦═════╗
║ ║ ║ ║. ║
║ ║ ║ ║. ║
║ ║ ║ ║. ║.
╠════════════════════╬═══════════════╬══════════╬═════╣

&#x200B;

https://redd.it/z0daiu
@r_bash
invoke a function only if a filename is supplied?

I have a function which is basically an entire bash noscript, it'll run but not do anything unless a filename is provided,

how would I have it so it does something like

echo 'Nothing happened, filename must be supplied'

How do I go about this?

https://redd.it/z0pyzf
@r_bash
Hi guys, new to bash noscripting. Can anyone can help me with this noscript, please?

#!/usr/bin/bash

#count=10
read -p "Please insert a number less than 11: " $count

if $count -lt 5 ;
then
echo "The number is less than 5"

elif $count -gt 10 ;
then
echo "You chose a greater number than the one we asked."
echo "Exiting program now."
exit

else
echo "The number is greater than 5"
fi


\-------------

&#x200B;

Giving an error:

./conditional.sh: line 6: : -lt: unary operator expected
./conditional.sh: line 10: [: -gt: unary operator expected
The number is greater than 5

Tried to google the error but still struggling with finding a solution. Thanks guys

[https://redd.it/z0v1u0

@r_bash
CIDR to netmask/subnet conversion ?

There are a lot of noscripts out there doing subnet expansion, cidr-2-netmask, finding subnet from /class and so on.

I need something very specific and I couldn't find anything.

I need to "transform" subnets to this form: 1.2.3.0/24 -> 1.2.3.0-1.2.3.254

10.20.0.0/16 \-> 10.20.0.0-10.20.255.254 and so on...

Or anything that an rbldnsd could accept:



### ip4set Dataset

A set of IP addresses or CIDR address ranges, together with A andTXT resulting values. IP addresses are specified one per line, by an IPaddress prefix (initial octets), complete IP address, CIDR range, or IPprefix range (two IP prefixes or complete addresses delimited bya dash, inclusive). Examples, to specify 127.0.0.0/24:

127.0.0.0/24 127.0.0 127/24 127-127.0.0 127.0.0.0-127.0.0.255 127.0.0.1-255to specify 127.16.0.0-127.31.255.255: 127.16.0.0-127.31.255.255 127.16.0-127.31.255 127.16-127.31 127.16-31 127.16.0.0/12 127.16.0/12 127.16/12

&#x200B;

But except /24 which is easy we also got /12 /11 / 16 /15 and almost any subnet you can imagine.

https://redd.it/z10c43
@r_bash
Help with a simple noscript

I’m trying to write a simple noscript that asks for 2 numbers from the user, checks if the 2nd is 0, asks again if so. But if not it divides the first by the second.

https://redd.it/z1drxh
@r_bash
wrote my first bash noscript today!

It is a very beginner noscript, which I hope to work on even more. My goal is to some how have my noscript start up on the end of a docker run command and automatically port forward my chosen ports so I can access the WUI on my host machine. Also trying to find a way to find system IP and store it in a variable in the bash noscript.

My noscript

# ! /bin/bash

read -p “what port?: “ PORT

echo “you chose $PORT “

read -p “tcp or udp?: “ PROTOCOL

echo “port forwarding $PORT/$PROTOCOL “

sudo ufw allow $PORT/PROTOCOL

sudo system restart ufw

https://redd.it/z1htfc
@r_bash
What's a terminal and what can I do with it? Note I'm asking this while already using it daily as a dev. But I still have 0 conceptual understanding of how computers are designed further down...

It's all so random if you're self-taught. You have 1000s of beginner videos but nobody explains to you what the hell this thing actually is deep down there. When the first terminal or when the first shell (whatever that is) was built, what was it supposed to solve?

Why do we have bash, zsh, and so on? Why do they all feel the same but are still different somehow?

What does it really do? If I echo something is it stored anywhere? What is stored when how? Can I create functions with it? Is what I write in the terminal turning complete? If not why not?

And whatever I have not asked, please just explain this damn thing :)

https://redd.it/z1r0kb
@r_bash
Should I care about how things break?
https://redd.it/z1ykk6
@r_bash
for loop in bash

how do i insert i into the awk statement:

for i in 3 4 5 6 7 8 9 10
do
awk -F',' '{sum+=$i;} END{print sum;}' crimedata-australia.csv

done

https://redd.it/z21j7r
@r_bash
noscript to install latest ImageMagick from source; covers all the bases

Wanted to share this noscript that I use when standing up VMs of mine that do some image processing. It curls the latest ImageMagick source code archive from imagemagick.org, verifies archive integrity, compiles, installs, and double-checks that it's working. Lots of sanity checks throughout.

Suggestions on technicalities, best practices, and aesthetics all welcome! Either here or via the gist.

https://gist.github.com/timoteostewart/16624088e656d336a2a862778788378a

https://redd.it/z28b01
@r_bash
Extracting a date from a variable

So I am making this one noscript where information are stored inside of another file and I want to take out just the date portion of each line that has an appointment. So far, I have this

`while read line`
`do`
`lineDate=\`echo $line | cut -c4-13\` #returns only the calendar date of the current line`
`done`

This works okay for the format of my lines in the file which look like this:
1| 22/11/2022 Doctor 12:30:00 - 14:00:00

However, once my appointment count reaches double or triple digits, then the cut will not be accurate anymore since the extra digits are moving the line forward a bit. Rather than reformat all the lines forward, anticipating the many digits. Is there a way for me to use sed to extract the date only? So from line one, lineDate would equal 22/11/2022. I am not sure of the format to use for this as I want ##/##/####.

https://redd.it/z2egl8
@r_bash
Homework questions.

Yes homework questions are allowed, but do remember the point of homework is for ***YOU*** to learn the material not us.
Here are some guidelines on how to get the best answer to help you learn.

**What we like:**

* Provide full context. Don't just drop a question without details.
* Tell us exactly what you need to solve and what information you've been given.
* Include any specific restrictions given by your professor.
* If you can't get yourself started, that's OK, but do tell us and we will see if we can get you going without just spoon feeding you. It really is better for you and better for everyone.
* Tell us what you've tried already, it will help with explaining the best future direction.
* Make a start on solving it, share your code and what errors you are seeing. *Share error messages exactly.*


**What we don't like:**

* "Do it for me, with complete explanation please"
* URGENT, DUE IN 15 MINUTES, or other phrases in ALL CAPS.
* People who delete their question once they get an answer.

**When you share code, do it in a way that works for everyone.**

* Share code, not pictures of code. We don't want to work from a screenshot or a photo of a terminal.
* If your noscript is longer than 30 or so lines, it might be better to share it via a code service like github or via a pastebin.
* Shorter noscripts or code snippets can just be included in your post.
* When you paste code into your question, ideally don't use the 'fancypants' editor because the code will be broken for users of old reddit.
* When you use 'markdown' mode or old.reddit then please leave 1 blank line before your noscript and 4 spaces before each line to get the correct formatting.
* Try running your code through shellcheck before (link in sidebar) it will catch many errors and offer suggestions for common problems and might save you some time.

https://redd.it/z2gzzi
@r_bash
Filling username & password through noscript

To use my college wifi, I have to open the auth. page and fill the username & password everytime.

I want to automate it such that the noscript open the site & fill the username & password and submit it by itself.

How can I achieve this?

https://redd.it/z2mblv
@r_bash
Delete last 3 lines of file

I'm trying to find a quick/dirty way to just delete the last lines from a file without opening it. So for example, something similar to this:

$cat test
first line
second line
third line
forth line
fifth line
$ head -n -3 test > test2
$ cat test2
first line
second line

Like this works, but now I've got to delete test and mv test2 into test. This whole process is just far too cumbersome.

I tried using the below, but unfortunately it results in test being empty. It appears to be an order of operations issue where it is trying to overwrite a file it's trying to get data from, and ends up with test having a completely empty file.

$ head -n -3 test > test

What I need is some sort of buffer to hold the output of $ head -n -3 test, which can then be used as an input buffer for a file. Not really sure how to do that.

https://redd.it/z2nc8m
@r_bash
Hi again!

Thanks for the help in advance. Today I looked for some until loops again, however, I got a bit confused between the while and the until loop.

Here is my while loop:

read -r -p "Please insert your number 1 -10: " number

while $number -le 10
do
echo "Your number is $number."
number=$(( number+1 ))
done

Here below is my until loop:

read -r -p "Please insert your number 1 -10: " number

until $number -eq 10
do
echo "Your number is $number."
number=$(( number+1 ))
done

Still not pretty sure the differences between them. Kindly asking if someone would have more information and explain it, please. Really appreciate it guys!

https://redd.it/z2lyhw
@r_bash
lobash: a modern, safe, powerful library for Bash noscript development

## What is Lobash?

Due to its complex syntaxes with symbols, and Unix commands are different in platforms such like BSD and GNU utilities have different options and behaviors with same command name, Bash noscript development is complex and fallible.

Javanoscript has a powerful library Lodash for simplifying development. So I build Lobash to do similar works for shell development.

Lobash provides collections of functions to improve efficiency of shell development. It is compatible with Bash 4.0+ and MacOS/Linux/Alpine/Busybox systems.

It is implemented with pure bash noscript.

## Features

* Modular and easy to use. One module one Function.
* Semantic functions instead of recondite bash expressions, substitutions, expansions.
* Rich Functions. Over 120+ modules provided.
* Robust and Safe. Over 700+ test cases tested. Tested in Linux and MacOS with Bash 4.0\~5.2.
* Fast. 0.058s to load Lobash completely.
* Compatible with MacOS/Linux/Alpine/Busybox systems.
* Compatible with Bash 4.0 and higher versions.

\------

Today it released v0.5.0. If you like it, please click the Star button. Thank you.

[https://github.com/adoyle-h/lobash](https://github.com/adoyle-h/lobash)

https://redd.it/z2vgfi
@r_bash