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
\-------------
​
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
#!/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
\-------------
​
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
reddit
Hi guys, new to bash noscripting. Can anyone can help me with this...
#!/usr/bin/bash #count=10 read -p "Please insert a number less than 11: " $count if [ $count -lt 5 ]; then echo "The...
Need assistance with bash noscripting on renaming files by inserting a suffix to the file name before the file's extension. This is the best I could come with help of others on this code. No idea how to proceed further. Total rookie here! Any help will make be grateful.
https://stackoverflow.com/questions/74519923/bash-noscript-for-school-assignment-as-far-as-my-experience-is-not-more-than-a-5
https://redd.it/z0zzez
@r_bash
https://stackoverflow.com/questions/74519923/bash-noscript-for-school-assignment-as-far-as-my-experience-is-not-more-than-a-5
https://redd.it/z0zzez
@r_bash
Stack Overflow
Bash noscript for school assignment, as far as my experience is not more than a 5 year kid
Write a noscript renaming files by inserting a suffix to the file name before the file's extension. For example, if the suffix is "sfx", the renaming should be done in the following way:
&q...
&q...
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
​
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
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
​
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
reddit
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...
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
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
reddit
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...
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
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
reddit
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...
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
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
reddit
What's a terminal and what can I do with it? Note I'm asking this...
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...
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
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
reddit
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;}'...
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
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
Gist
install latest ImageMagick on Linux from source
install latest ImageMagick on Linux from source. GitHub Gist: instantly share code, notes, and snippets.
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
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
reddit
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...
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
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
reddit
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...
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
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
reddit
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...
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
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
reddit
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: ...
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
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
reddit
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...
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
## 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
GitHub
GitHub - adoyle-h/lobash: A modern, safe, powerful utility/library for Bash noscript development.
A modern, safe, powerful utility/library for Bash noscript development. - adoyle-h/lobash
grep: warning: stray \ before /
I am trying to run this noscript.
#!/bin/sh
movie=$(curl -s https://1337x.to/search/$query/1/ | grep -Eo "torrent\/0-9{7}\/a-zA-Z0-9?%-/" | head -n 1)
magnet=$(curl -s https://1337x.to/$movie | grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]" | head -n 1)
peerflix $magnet -l -v
I get the error of grep: warning: stray \\ before / . I have tried to get rid of the \\ before the /. This did not work. Can anyone help me?
https://redd.it/z2vfx0
@r_bash
I am trying to run this noscript.
#!/bin/sh
movie=$(curl -s https://1337x.to/search/$query/1/ | grep -Eo "torrent\/0-9{7}\/a-zA-Z0-9?%-/" | head -n 1)
magnet=$(curl -s https://1337x.to/$movie | grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]" | head -n 1)
peerflix $magnet -l -v
I get the error of grep: warning: stray \\ before / . I have tried to get rid of the \\ before the /. This did not work. Can anyone help me?
https://redd.it/z2vfx0
@r_bash
How to pass an associative array to another noscript
I want to pass an associative array in noscript1.sh to noscript2.sh. Here is what I have:
noscript1.sh:
declare -A queues
queues=( "key1"="value1" "key2"="value2" "key3"="value3" "key4"="value4" )
call noscript2:
noscript2.sh "$param1" "$param2" "$param3" "${queues@}"
noscript2.sh:
arg1=$1
arg2=$2
arg3=$3
declare -A arg4=$4
The associative array in noscript1 is fine. I can loop through the array and see its elements. However, when I tried to pass it to noscript2.sh, I can't see any of the elements in arg4. Thanks in advance.
https://redd.it/z2xyv5
@r_bash
I want to pass an associative array in noscript1.sh to noscript2.sh. Here is what I have:
noscript1.sh:
declare -A queues
queues=( "key1"="value1" "key2"="value2" "key3"="value3" "key4"="value4" )
call noscript2:
noscript2.sh "$param1" "$param2" "$param3" "${queues@}"
noscript2.sh:
arg1=$1
arg2=$2
arg3=$3
declare -A arg4=$4
The associative array in noscript1 is fine. I can loop through the array and see its elements. However, when I tried to pass it to noscript2.sh, I can't see any of the elements in arg4. Thanks in advance.
https://redd.it/z2xyv5
@r_bash
reddit
How to pass an associative array to another noscript
I want to pass an associative array in noscript1.sh to noscript2.sh. Here is what I have: noscript1.sh: declare -A queues queues=( ["key1"]="value1"...
Need help with sed and variables
Hi Everyone,
I've put together a sed for vnstat xml output for my openwrt router. (trying to get a cleaner output) My sed works if I have the year (2022) and month (11) in the sed command. When I replace 2022 with $y and 11 with $m, it doesnt work, no change in the output, like it doesn't recognize it.
​
The file looks like this:
2022 11 21 05:00 474322562 15172268
2022 11 21 06:00 536016232 651897033
2022 11 21 07:00 184569685 109642704
Here is what works (without the variables, just normal ):
vnstat --xml |grep -hnr "hour id" | sed "s/<^>>/ /g; s/2022//g; s/ //g; s/ 00/:00/g; s/11 /11-/g" | cut -d " " -f2- > houroutput.xml
-----------------------------------------------
and the output looks good:
11-21 05:00 474322562 15172268
11-21 06:00 536016232 651897033
11-21 07:00 184569685 109642704
​
my noscript looks like with the variables in sed, I even replaced the single quotes with double, but no change in output.
#!/bin/sh
y="date +%Y"
m="date +%m"
vnstat --xml |grep -hnr "hour id" | sed "s/<[^>]>/ /g; s/$y//g; s/ //g; s/ 00/:00/g; s/$m /$m-/g" | cut -d " " -f2- > houroutput.xml
Output doesnt look good:
2022 11 21 05:00 474322562 15172268
2022 11 21 06:00 536016232 651897033
2022 11 21 07:00 184569685 109642704
https://redd.it/z31cfq
@r_bash
Hi Everyone,
I've put together a sed for vnstat xml output for my openwrt router. (trying to get a cleaner output) My sed works if I have the year (2022) and month (11) in the sed command. When I replace 2022 with $y and 11 with $m, it doesnt work, no change in the output, like it doesn't recognize it.
​
The file looks like this:
2022 11 21 05:00 474322562 15172268
2022 11 21 06:00 536016232 651897033
2022 11 21 07:00 184569685 109642704
Here is what works (without the variables, just normal ):
vnstat --xml |grep -hnr "hour id" | sed "s/<^>>/ /g; s/2022//g; s/ //g; s/ 00/:00/g; s/11 /11-/g" | cut -d " " -f2- > houroutput.xml
-----------------------------------------------
and the output looks good:
11-21 05:00 474322562 15172268
11-21 06:00 536016232 651897033
11-21 07:00 184569685 109642704
​
my noscript looks like with the variables in sed, I even replaced the single quotes with double, but no change in output.
#!/bin/sh
y="date +%Y"
m="date +%m"
vnstat --xml |grep -hnr "hour id" | sed "s/<[^>]>/ /g; s/$y//g; s/ //g; s/ 00/:00/g; s/$m /$m-/g" | cut -d " " -f2- > houroutput.xml
Output doesnt look good:
2022 11 21 05:00 474322562 15172268
2022 11 21 06:00 536016232 651897033
2022 11 21 07:00 184569685 109642704
https://redd.it/z31cfq
@r_bash
reddit
Need help with sed and variables
Hi Everyone, I've put together a sed for vnstat xml output for my openwrt router. (trying to get a cleaner output) My sed works if I have the...
Somewhat probably generic post
What's your personal 'ah ha' moment when getting into learning bash? What made you think, "oh damn I need to know this"
https://redd.it/z3riln
@r_bash
What's your personal 'ah ha' moment when getting into learning bash? What made you think, "oh damn I need to know this"
https://redd.it/z3riln
@r_bash
reddit
Somewhat probably generic post
What's your personal 'ah ha' moment when getting into learning bash? What made you think, "oh damn I need to know this"
my first semi noob noscript - Loop through list of trackers and test if they are alive using nc
https://gist.github.com/neuthral/0ff41380958321d69888fead29d510ee
https://redd.it/z3rcka
@r_bash
https://gist.github.com/neuthral/0ff41380958321d69888fead29d510ee
https://redd.it/z3rcka
@r_bash
Gist
Loop through list of trackers and test if they are alive using nc
Loop through list of trackers and test if they are alive using nc - loop.sh
read contents of a file into a variable with bash without invoking other commands?
Is there some internal bash way to do this?
x=$(cat /proc/uptime)
And i am not thinking about the line-by-line "while read l; do bla bla; done < file" (for various reasons).
https://redd.it/z3ue97
@r_bash
Is there some internal bash way to do this?
x=$(cat /proc/uptime)
And i am not thinking about the line-by-line "while read l; do bla bla; done < file" (for various reasons).
https://redd.it/z3ue97
@r_bash
reddit
read contents of a file into a variable with bash without invoking...
Is there some internal bash way to do this? x=$(cat /proc/uptime) And i am not thinking about the line-by-line "while read l; do bla bla; done <...