bashunit 0.8
The new release for bashunit is ready!
You can now define mocks, spies, among many other features.
\- Check the improved Getting Started page
\- Check the full CHANGELOG for the new release 0.8
bashunit is a game changer for the bash ecosystem.
​
>The simplest testing library for bash noscripts - https://bashunit.typeddevs.com/
​
https://redd.it/17311bi
@r_bash
The new release for bashunit is ready!
You can now define mocks, spies, among many other features.
\- Check the improved Getting Started page
\- Check the full CHANGELOG for the new release 0.8
bashunit is a game changer for the bash ecosystem.
​
>The simplest testing library for bash noscripts - https://bashunit.typeddevs.com/
​
https://redd.it/17311bi
@r_bash
Typeddevs
Getting Started | bashunit
Test your bash noscripts in the fastest and simplest way, discover the most modern bash testing library.
From Complex to Simple
Hello, r/bash!
It's curious how things can get complicated in so many ways. I created a noscript that I use in my tmux.conf to retrieve the IPv4 address of my network interfaces and display it in my status bar, following a set of priorities. Depending on which interface is active, it prioritizes one over the other. Code of my first version:
#!/bin/bash
INET=''
if [[ -f /sys/class/net/tun0/operstate ]]; then
INET='tun0'
elif [[ $(< /sys/class/net/eth0/operstate) == "up" ]]; then
INET='eth0'
else
INET='wlan0'
fi
echo $(ip -4 addr show $INET | grep -oP "(?<=inet\s)\d+(\.\d+){3}")
This noscript worked 'fine', at least it served its purpose for several months. My problem was that sometimes the interface names didn't match, so I decided to make an array of names:
#!/bin/bash
INET=''
name=('tun0' 'eth0' 'wlan0')
if [[ -f /sys/class/net/${name[1]}/operstate ]]; then
INET=${name[1]}
elif [[ $(< /sys/class/net/${name[2]}/operstate) == "up" ]]; then
INET=${name[2]}
else
INET=${name[3]}
fi
echo $(ip -4 addr show $INET | grep -oP "(?<=inet\s)\d+(\.\d+){3}")
This works 'better' because I either just have to change the name within the array for the interface I want to prioritize or directly change the interface name in the network interface configuration.
I thought for a moment, why not simply use a regex to search for the interface name and then find the assigned IP of that interface, and this was the result:
#/bin/bash
inets=$(ip addr | awk '/^[0-9]+: (.*):/ {print $2}')
if [[ $inets =~ tun[0-9]+ && $(< /sys/class/net/${BASH_REMATCH[0]}/operstate) == "up" ]]; then
inet="${BASH_REMATCH[0]}"
elif [[ $inets =~ eth[0-9]+|enp.*[0-9]+ && $(< /sys/class/net/${BASH_REMATCH[0]}/operstate) == "up" ]]; then
inet="${BASH_REMATCH[0]}"
elif [[ $inets =~ wlan[0-9]+ && $(< /sys/class/net/${BASH_REMATCH[0]}/operstate) == "up" ]]; then
inet="${BASH_REMATCH[0]}"
else
echo [no inet or ip]
exit 1
fi
echo $(ip -4 addr show $inet | grep -oP "(?<=inet\s)\d+(\.\d+){3}")
This noscript once again works, and I don't have to change the interface name or do much, but I thought, 'This seems too complicated. Is there an easier way to do this?'
Reading a bit about how the `ip` command works, I realized that there's a `-o` flag I wasn't aware of, and this simplified the problem a lot. This way, I could parse the information with simple `awk` and regex. Here was the result:
#/bin/bash
ip -o -4 addr show | awk '/tun[0-9]+/ {print $4; exit}
/eth[0-9]+|enp.*[0-9]+/ {print $4; exit}
/wlan[0-9]+/ {print $4; exit}'
This works very well, and I'm quite happy with the final result. But it got me thinking, it all became complicated because I didn't know the `ip` command's arguments well. I wanted to share this experience with you in case it happens to any of you, so you can find something useful in it. But tell me, r/bash, has something similar ever happened to you? I mean, has a noscript ever become overly complicated, and then you found a much simpler way to do it?
If you think there's an even easier/better way to accomplish this task, I'd love to hear from you.
https://redd.it/173h2xz
@r_bash
Hello, r/bash!
It's curious how things can get complicated in so many ways. I created a noscript that I use in my tmux.conf to retrieve the IPv4 address of my network interfaces and display it in my status bar, following a set of priorities. Depending on which interface is active, it prioritizes one over the other. Code of my first version:
#!/bin/bash
INET=''
if [[ -f /sys/class/net/tun0/operstate ]]; then
INET='tun0'
elif [[ $(< /sys/class/net/eth0/operstate) == "up" ]]; then
INET='eth0'
else
INET='wlan0'
fi
echo $(ip -4 addr show $INET | grep -oP "(?<=inet\s)\d+(\.\d+){3}")
This noscript worked 'fine', at least it served its purpose for several months. My problem was that sometimes the interface names didn't match, so I decided to make an array of names:
#!/bin/bash
INET=''
name=('tun0' 'eth0' 'wlan0')
if [[ -f /sys/class/net/${name[1]}/operstate ]]; then
INET=${name[1]}
elif [[ $(< /sys/class/net/${name[2]}/operstate) == "up" ]]; then
INET=${name[2]}
else
INET=${name[3]}
fi
echo $(ip -4 addr show $INET | grep -oP "(?<=inet\s)\d+(\.\d+){3}")
This works 'better' because I either just have to change the name within the array for the interface I want to prioritize or directly change the interface name in the network interface configuration.
I thought for a moment, why not simply use a regex to search for the interface name and then find the assigned IP of that interface, and this was the result:
#/bin/bash
inets=$(ip addr | awk '/^[0-9]+: (.*):/ {print $2}')
if [[ $inets =~ tun[0-9]+ && $(< /sys/class/net/${BASH_REMATCH[0]}/operstate) == "up" ]]; then
inet="${BASH_REMATCH[0]}"
elif [[ $inets =~ eth[0-9]+|enp.*[0-9]+ && $(< /sys/class/net/${BASH_REMATCH[0]}/operstate) == "up" ]]; then
inet="${BASH_REMATCH[0]}"
elif [[ $inets =~ wlan[0-9]+ && $(< /sys/class/net/${BASH_REMATCH[0]}/operstate) == "up" ]]; then
inet="${BASH_REMATCH[0]}"
else
echo [no inet or ip]
exit 1
fi
echo $(ip -4 addr show $inet | grep -oP "(?<=inet\s)\d+(\.\d+){3}")
This noscript once again works, and I don't have to change the interface name or do much, but I thought, 'This seems too complicated. Is there an easier way to do this?'
Reading a bit about how the `ip` command works, I realized that there's a `-o` flag I wasn't aware of, and this simplified the problem a lot. This way, I could parse the information with simple `awk` and regex. Here was the result:
#/bin/bash
ip -o -4 addr show | awk '/tun[0-9]+/ {print $4; exit}
/eth[0-9]+|enp.*[0-9]+/ {print $4; exit}
/wlan[0-9]+/ {print $4; exit}'
This works very well, and I'm quite happy with the final result. But it got me thinking, it all became complicated because I didn't know the `ip` command's arguments well. I wanted to share this experience with you in case it happens to any of you, so you can find something useful in it. But tell me, r/bash, has something similar ever happened to you? I mean, has a noscript ever become overly complicated, and then you found a much simpler way to do it?
If you think there's an even easier/better way to accomplish this task, I'd love to hear from you.
https://redd.it/173h2xz
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
would you evaluate this noscript? cp + chown
I made a noscript to migrate old user data to my new current user. As things turn out, I wrote this noscript to copy data from anywhere outside the loggedin user to the loggedin user and change the ownership of the files/directories to USER:USER.
However, as this is a pretty delecate process, I'm a little cautious to just use it. Would you mind to have a look at the noscript to evaluate it's validity? I provided comments for each step to clarify the reasoning behind it.
https://redd.it/173qk8b
@r_bash
I made a noscript to migrate old user data to my new current user. As things turn out, I wrote this noscript to copy data from anywhere outside the loggedin user to the loggedin user and change the ownership of the files/directories to USER:USER.
However, as this is a pretty delecate process, I'm a little cautious to just use it. Would you mind to have a look at the noscript to evaluate it's validity? I provided comments for each step to clarify the reasoning behind it.
#!/bin/bash
### arguments
[[ ${#@} != 2 ]] && exit 1 # 2 arguments are expected
### source
source=$(readlink -e "$1") # convert relative paths to absolute paths if
necessary; will filter non-existing files or paths
# errors
[[ "$source" = "" ]] && exit 2 # file or paht invalid
[[ "$source" = "/" ]] && exit 3 # copying / is not allowed
[[ "$source" = "$HOME"* ]] && exit 4 # copying from the current user dirs is not
allowed
[[ "$HOME" != "${HOME//"$source/"/}" ]] && exit 5 # copying from a path
containing the current user dirs as subdirectory is not allowed
### destination
destination="$(readlink -e "$2")" # convert relative paths to absolute paths if
necessary; will filter non-existing files or paths; however, in case of copying a
file that doesn't exist yet will also result in a empty string
if [[ -d "$source" || -d "$destination" ]]; then
add="/$(basename "$source")"
# if a dir is copied, get the dir name for the chown command
# or
# for copying a file: if only a valid path is provided as destination, get
the file name for the chown command
elif [[ -n "$(readlink -e "$(dirname "$2")")" ]]; then # for copying a file with
file name provided to the destination; check whether the path is valid
destination="$(readlink -e "$(dirname "$2")")/$(basename "$2")" # set the
absolute path and the file name as destination
fi
# errors
[[ -f "$(readlink -e "$destination$add")" ]] && exit 6 # case copying a file: if
file already exist (ok, this might be redundant because I use the -n flag for the
cp command)
[[ -d "$destination/$(basename "$source")" ]] && exit 7 # case copying a
directory: if the directory already exists at the destination
[[ -d "$source" && ! -d "$destination" ]] && exit 8 # if the destination path is
invalid
[[ "$destination" != "$HOME"* ]] && exit 9 # copying outside home of the current
user is not allowed
### operations
sudo cp -rpn "$source" "$destination"
echo "$source copied to $destination"
sudo chown -R $USER: "$destination$add"
echo "$USER owns $destination$add"
https://redd.it/173qk8b
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
12 Super Cool Terminal Easter Eggs
https://medium.com/@tinplavec/12-super-cool-terminal-easter-eggs-edf6b48eb32c
I would like to share my article where I list cool 'Easter egg' programs you can try in your Bash shell. I know this article isn't directly related to noscripting, but it's still related to Bash and I hope you have fun trying out all these programs 😄.
And of course, comment if you know some other Easter eggs.
https://redd.it/173v4su
@r_bash
https://medium.com/@tinplavec/12-super-cool-terminal-easter-eggs-edf6b48eb32c
I would like to share my article where I list cool 'Easter egg' programs you can try in your Bash shell. I know this article isn't directly related to noscripting, but it's still related to Bash and I hope you have fun trying out all these programs 😄.
And of course, comment if you know some other Easter eggs.
https://redd.it/173v4su
@r_bash
Medium
12 Super Cool Terminal Easter Eggs You Need To Try
Terminal is quite a powerful tool. You will often see people bragging about their knowledge to use terminal commands. Indeed, using…
Am I the only one who thinks that bash is ugly?
Don't get me wrong, I love it, it's just...
​
https://preview.redd.it/m1xrt2qzd8tb1.png?width=886&format=png&auto=webp&s=2f8c77f3d700db91423654327a9d2c6df4ff3b6b
Even if it's clear and I consider it a good language everything feels so cluttered
https://redd.it/17414vj
@r_bash
Don't get me wrong, I love it, it's just...
​
https://preview.redd.it/m1xrt2qzd8tb1.png?width=886&format=png&auto=webp&s=2f8c77f3d700db91423654327a9d2c6df4ff3b6b
Even if it's clear and I consider it a good language everything feels so cluttered
https://redd.it/17414vj
@r_bash
Best practices for noscripting in the command line?
Say I entering something simple
for i in {1..5}; do
> echo $i
> done
When I press the up arrow, it will show this
Now if we have a more complicated example with embedded for loops, cases, etc, I wouldn't be able to understand the code that is a singleline. Code with indents and linebreaks are much easier to debug, so if you had to enter long and complicated code into the commandline and had to modify it again by pressing the up arrow, how would you understand it? Is it possible to have the indents and the newlines it was originally entered with when we press the up arrow? I know we should enter our noscripts through Vim but sometimes for onetime things, I enter directly onto the command line.
https://redd.it/17492ek
@r_bash
Say I entering something simple
for i in {1..5}; do
> echo $i
> done
When I press the up arrow, it will show this
for i in {1..5}; do echo $i; done. Not too difficult to read.Now if we have a more complicated example with embedded for loops, cases, etc, I wouldn't be able to understand the code that is a singleline. Code with indents and linebreaks are much easier to debug, so if you had to enter long and complicated code into the commandline and had to modify it again by pressing the up arrow, how would you understand it? Is it possible to have the indents and the newlines it was originally entered with when we press the up arrow? I know we should enter our noscripts through Vim but sometimes for onetime things, I enter directly onto the command line.
https://redd.it/17492ek
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Flacky "here documents"
"here documents" are really good and it saves you from having to repeat a lot of echo or printf statements. They are also very simple, nothing complicated about them.
On Ubuntu bash they are a hit and miss if they work. Often the the runtime interpreter gets confused. Problems don't seem to be related to contents, even with plain text the sometimes may not work
I've been using them like this for a long time on in Korn, in Bash they should be the same. Any ideas why?
cat << msgend
This message was written on $(date) about when I $(touch this).
But its not as bad as last Tuesday.
msgend
​
​
​
​
https://redd.it/174b9ka
@r_bash
"here documents" are really good and it saves you from having to repeat a lot of echo or printf statements. They are also very simple, nothing complicated about them.
On Ubuntu bash they are a hit and miss if they work. Often the the runtime interpreter gets confused. Problems don't seem to be related to contents, even with plain text the sometimes may not work
I've been using them like this for a long time on in Korn, in Bash they should be the same. Any ideas why?
cat << msgend
This message was written on $(date) about when I $(touch this).
But its not as bad as last Tuesday.
msgend
​
​
​
​
https://redd.it/174b9ka
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
This media is not supported in your browser
VIEW IN TELEGRAM
play - TUI playground for your favorite programs, such as grep, sed and awk
https://redd.it/174rsd6
@r_bash
https://redd.it/174rsd6
@r_bash
Help Moving files in a directory (SCRIPT)
Hey y'all, im trying to learn Bash noscripting and figured i'd start with something that will be useful to me.
Objective: Allow users (me) to be able to select which source + destination to move files from and to. The goal is to be able to run the noscript and move everything in my downloads folder to wherever i may want it. But i also want to be able to do this with any directory.
​
#!/bin/bash
echo Can you show me where the source directory is?
read source
echo $source is the source directory. What is the Destination directory?
read dest
cd $(echo $source)
ls
pwd
mv -v $dest
If i replace $dest with the file path instead of using the variable created by "read" then it works flawlessly. I tried to add $HOME as a prefix to $data but that wasn't working.
​
mv -v ~/Documents
Any tips would be greatly appreciated as i am new to noscripting and fairly new to linux. TIA
https://redd.it/174zmfv
@r_bash
Hey y'all, im trying to learn Bash noscripting and figured i'd start with something that will be useful to me.
Objective: Allow users (me) to be able to select which source + destination to move files from and to. The goal is to be able to run the noscript and move everything in my downloads folder to wherever i may want it. But i also want to be able to do this with any directory.
​
#!/bin/bash
echo Can you show me where the source directory is?
read source
echo $source is the source directory. What is the Destination directory?
read dest
cd $(echo $source)
ls
pwd
mv -v $dest
If i replace $dest with the file path instead of using the variable created by "read" then it works flawlessly. I tried to add $HOME as a prefix to $data but that wasn't working.
​
mv -v ~/Documents
Any tips would be greatly appreciated as i am new to noscripting and fairly new to linux. TIA
https://redd.it/174zmfv
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Does going through the entire noscript just to find the help function slow down noscript?
My noscript looks like this
Help function
All the other functions
My reasoning is that if the user just wants to use the -h flag then the noscript shouldn't pass through all the main functions which aren't going to be used. But having the help function at the beginning looks ugly in my noscript so I want to move it down. But then the noscript (I think) would have to read through all the main functions which aren't going to be used which would slow down the noscript.
​
https://redd.it/1753fda
@r_bash
My noscript looks like this
Help function
All the other functions
My reasoning is that if the user just wants to use the -h flag then the noscript shouldn't pass through all the main functions which aren't going to be used. But having the help function at the beginning looks ugly in my noscript so I want to move it down. But then the noscript (I think) would have to read through all the main functions which aren't going to be used which would slow down the noscript.
​
https://redd.it/1753fda
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
ssh user maker
Guys, I’ve created a bash noscript for creating ssh users on server with expire date,and speed limit, would be happy if you check it out and tell me your feedbacks, feel free to commit to it and if it have any problems please let me know.
Btw README file was generated by ChatGPT.
https://github.com/momalekiii/sshmaker
https://redd.it/175gqvy
@r_bash
Guys, I’ve created a bash noscript for creating ssh users on server with expire date,and speed limit, would be happy if you check it out and tell me your feedbacks, feel free to commit to it and if it have any problems please let me know.
Btw README file was generated by ChatGPT.
https://github.com/momalekiii/sshmaker
https://redd.it/175gqvy
@r_bash
GitHub
GitHub - momalekiii/sshmaker: Simple noscript for create ssh users and manage usage.
Simple noscript for create ssh users and manage usage. - GitHub - momalekiii/sshmaker: Simple noscript for create ssh users and manage usage.
This media is not supported in your browser
VIEW IN TELEGRAM
[Help] tput setab colors stretch to terminal width on term scroll. (noscript in comments)
https://redd.it/175m914
@r_bash
https://redd.it/175m914
@r_bash
Building options from array. What am I doing wrong?
I am trying to find a range of files, but I want to be able to keep the extensions in an array. I try to echo the final find command and it echos correctly, but if I try run it, I just get a null result. Copy and pasting the echoed command returns a result.
#!/bin/bash
extarray=( "3gp" "mp4" "mkv" "m4a" "webm" "mpg" "mpeg" "avi" "vob" "asf" "wmf" )
for ((n=0; n<${#extarray@}; n++))
do
if [ $n == "0" ]
then
optiname="-iname \".${extarray[$n]}\""
else
temp=$optiname
optiname="$temp -o -iname \".${extarray$n}\""
fi
done
echo "find . -type f \( $optiname \) | sort"
find . -type f \( "$optiname" \)
​
https://redd.it/1760ifx
@r_bash
I am trying to find a range of files, but I want to be able to keep the extensions in an array. I try to echo the final find command and it echos correctly, but if I try run it, I just get a null result. Copy and pasting the echoed command returns a result.
#!/bin/bash
extarray=( "3gp" "mp4" "mkv" "m4a" "webm" "mpg" "mpeg" "avi" "vob" "asf" "wmf" )
for ((n=0; n<${#extarray@}; n++))
do
if [ $n == "0" ]
then
optiname="-iname \".${extarray[$n]}\""
else
temp=$optiname
optiname="$temp -o -iname \".${extarray$n}\""
fi
done
echo "find . -type f \( $optiname \) | sort"
find . -type f \( "$optiname" \)
​
https://redd.it/1760ifx
@r_bash
Reddit
Explore this post and more from the bash community
Struggles of a noscripting noob
I decided to use a Windows subsystem for Linux, install Debian and play around with bash noscripting.
I have to say it has been somewhat frustrating. As a first attempt at something somewhat useful I decided to make a command function to start a new noscript.
I learned that functions don't even need a type declaration. you don't need to put the word function in the code for it to become a function.
I learned there is no one proper syntax for an if structure. There are multiple acceptable sysntaxes, but sometimes a space or lack of a space in the wrong place is fatal, while whether you use parens or square brackets might not matter.
Here is what I ended up sticking in the end of my .bashrc file:
function mbs { # command to make a new noscript
FILE=$1
echo $FILE
if [ $# -gt 0 \]
then
echo "%! /bin/bash" > $FILE
chmod u+x $FILE
echo "# $FILE" >> $FILE
nano $FILE
​
else echo "You need to supply a filename."
​
fi
}
The first improvement IMO would be to make sure it does not overwrite an existing file, but at least this is doing what I asked it to.
The reason for this post is just to express some surprise that the syntax of this language is important in some ways and not important in others. :D
https://redd.it/1769ezz
@r_bash
I decided to use a Windows subsystem for Linux, install Debian and play around with bash noscripting.
I have to say it has been somewhat frustrating. As a first attempt at something somewhat useful I decided to make a command function to start a new noscript.
I learned that functions don't even need a type declaration. you don't need to put the word function in the code for it to become a function.
I learned there is no one proper syntax for an if structure. There are multiple acceptable sysntaxes, but sometimes a space or lack of a space in the wrong place is fatal, while whether you use parens or square brackets might not matter.
Here is what I ended up sticking in the end of my .bashrc file:
function mbs { # command to make a new noscript
FILE=$1
echo $FILE
if [ $# -gt 0 \]
then
echo "%! /bin/bash" > $FILE
chmod u+x $FILE
echo "# $FILE" >> $FILE
nano $FILE
​
else echo "You need to supply a filename."
​
fi
}
The first improvement IMO would be to make sure it does not overwrite an existing file, but at least this is doing what I asked it to.
The reason for this post is just to express some surprise that the syntax of this language is important in some ways and not important in others. :D
https://redd.it/1769ezz
@r_bash
Reddit
Explore this post and more from the bash community
Looking for a Linux & Unix Discord Community?
Are you passionate about Linux and Unix? 🐧
Do you want to connect with like-minded individuals, from beginners to experts? 🧠
Then you've found your new home. We're all about fostering meaningful connections and knowledge sharing.
🤔 Why We Exist: At the heart of our community is a shared love for Linux and Unix. We're here to connect with fellow enthusiasts, regardless of where you are on your journey, and create a space where our shared passion thrives.
🤨 How We Do It: We foster a welcoming environment where open conversations are the norm. Here, you can share your experiences, ask questions, and deepen your knowledge alongside others who are equally passionate.
🎯 What We Offer:
🔹 Engaging Discussions: Our discussions revolve around Linux and Unix, creating a hub of knowledge-sharing and collaboration. Share your experiences, ask questions, and learn from each other.
🔹 Supportive Environment: Whether you're a newcomer or a seasoned pro, you'll find your place here. We're all about helping each other grow. Our goal is to create a friendly and supportive space where everyone, regardless of their level of expertise, feels at home.
🔹 Innovative Tools: Explore our bots, including "dlinux," which lets you create containers and run commands without leaving Discord—a game-changer for Linux enthusiasts.
🔹 Distro-Specific Support: Our community is equipped with dedicated support channels for popular Linux distributions, including but not limited to:
Arch Linux
CentOS
Debian
Fedora
Red Hat
Ubuntu
...and many more!
Why Choose Us? 🌐
Our server aligns perfectly with Discord's guidelines and Terms of Service, ensuring a safe and enjoyable experience for all members. 🧐 📜 ✔️
Don't take our word for it—come check it out yourself! 👀
Join our growing community of Linux and Unix enthusiasts today let's explore, learn, and share our love for Linux and Unix together. 🐧❤️
See you on the server! 🚀
https://discord.gg/unixverse
https://redd.it/176aqrh
@r_bash
Are you passionate about Linux and Unix? 🐧
Do you want to connect with like-minded individuals, from beginners to experts? 🧠
Then you've found your new home. We're all about fostering meaningful connections and knowledge sharing.
🤔 Why We Exist: At the heart of our community is a shared love for Linux and Unix. We're here to connect with fellow enthusiasts, regardless of where you are on your journey, and create a space where our shared passion thrives.
🤨 How We Do It: We foster a welcoming environment where open conversations are the norm. Here, you can share your experiences, ask questions, and deepen your knowledge alongside others who are equally passionate.
🎯 What We Offer:
🔹 Engaging Discussions: Our discussions revolve around Linux and Unix, creating a hub of knowledge-sharing and collaboration. Share your experiences, ask questions, and learn from each other.
🔹 Supportive Environment: Whether you're a newcomer or a seasoned pro, you'll find your place here. We're all about helping each other grow. Our goal is to create a friendly and supportive space where everyone, regardless of their level of expertise, feels at home.
🔹 Innovative Tools: Explore our bots, including "dlinux," which lets you create containers and run commands without leaving Discord—a game-changer for Linux enthusiasts.
🔹 Distro-Specific Support: Our community is equipped with dedicated support channels for popular Linux distributions, including but not limited to:
Arch Linux
CentOS
Debian
Fedora
Red Hat
Ubuntu
...and many more!
Why Choose Us? 🌐
Our server aligns perfectly with Discord's guidelines and Terms of Service, ensuring a safe and enjoyable experience for all members. 🧐 📜 ✔️
Don't take our word for it—come check it out yourself! 👀
Join our growing community of Linux and Unix enthusiasts today let's explore, learn, and share our love for Linux and Unix together. 🐧❤️
See you on the server! 🚀
https://discord.gg/unixverse
https://redd.it/176aqrh
@r_bash
Help with creating a bash code to compare two different files
Hello, everyone!
I'm currently encountering some challenges while working on a bash noscript in the Linux terminal to perform the following tasks:
1. Compare the values in the third column of two different files line by line.
2. If the values are different, save in a third output file the identifier from the second column of the input files, along with the corresponding values from both File 1 and File 2, similar to the "desired first output" example provided.
3. Additionally, create a fourth output file to tally the occurrences of each unique qualitative difference, taking into account the order (for example: 9690 0 ≠ 0 9690) while disregarding the identifier. This is illustrated in the "desired last output" example.
Any assistance or guidance in achieving this is greatly appreciated!
FILE 1
FILE2
DESIRED FIRST OUTPUT
DISIRED LAST OUTPUT
https://redd.it/176pcqr
@r_bash
Hello, everyone!
I'm currently encountering some challenges while working on a bash noscript in the Linux terminal to perform the following tasks:
1. Compare the values in the third column of two different files line by line.
2. If the values are different, save in a third output file the identifier from the second column of the input files, along with the corresponding values from both File 1 and File 2, similar to the "desired first output" example provided.
3. Additionally, create a fourth output file to tally the occurrences of each unique qualitative difference, taking into account the order (for example: 9690 0 ≠ 0 9690) while disregarding the identifier. This is illustrated in the "desired last output" example.
Any assistance or guidance in achieving this is greatly appreciated!
FILE 1
U E100033877L1C016R01601996031 0 140 0:106U E100033877L1C023R03303214633 0 140 0:106C E100033877L1C022R01901579971 27996 140 27996:1 0:7 27996:23 0:75C E100033877L1C023R02603225407 27996 140 0:32 27996:23 0:7 27996:1 0:3 27996:4 0:36C E100033877L1C020R02602000209 0 140 0:106C E100033877L1C023R03303214633 27996 140 27996:3 0:4 27996:5 0:94C E100033877L1C023R03101740491 9690 140 9690:13 0:8 9690:7 0:13 9690:9 0:56C E100033877L1C006R00200498634 9690 140 9690:71 0:35C E100033877L1C009R03603066069 27996 140 0:50 27996:2 0:1 27996:10 0:6 27996:11 0:26C E100033877L1C005R03300436825 27996 140 27996:3 0:6 27996:3 0:3 27996:5 0:86FILE2
U E100033877L1C016R01601996031 0 140 0:106U E100033877L1C023R03303214633 0 140 0:106C E100033877L1C022R01901579971 27996 140 27996:1 0:7 27996:23 0:75C E100033877L1C023R02603225407 27996 140 0:32 27996:23 0:7 27996:1 0:3 27996:4 0:36C E100033877L1C020R02602000209 27996 140 0:19 27996:4 0:3 27996:1 0:7 27996:23 0:49C E100033877L1C023R03303214633 27996 140 27996:3 0:4 27996:5 0:94U E100033877L1C023R03101740491 0 140 0:106U E100033877L1C006R00200498634 0 140 4840:106C E100033877L1C009R03603066069 4840 140 0:50 27996:2 0:1 27996:10 0:6 27996:11 0:26C E100033877L1C005R03300436825 27996 140 27996:3 0:6 27996:3 0:3 27996:5 0:86DESIRED FIRST OUTPUT
E100033877L1C020R02602000209 0 27996E100033877L1C023R03101740491 9690 0 E100033877L1C006R00200498634 9690 0 E100033877L1C009R03603066069 27996 4840DISIRED LAST OUTPUT
2 9690 0 1 0 279961 27996 4840https://redd.it/176pcqr
@r_bash
Reddit
Explore this post and more from the bash community
Best way setting arguments to noscript that is not able to read from the environment
Hello. I am working with a noscript that is not able to read variables from the environment and that I am not able to modify.
printenv
# a=123 b=234 c=345
# Script expects the variable content in arguments
./noscript para=123 parb=234 parc=345
What is the best way to handle a situation like this?
https://redd.it/176utr4
@r_bash
Hello. I am working with a noscript that is not able to read variables from the environment and that I am not able to modify.
printenv
# a=123 b=234 c=345
# Script expects the variable content in arguments
./noscript para=123 parb=234 parc=345
What is the best way to handle a situation like this?
https://redd.it/176utr4
@r_bash
Reddit
Explore this post and more from the bash community
Help... I got confused by the bash statement(while, if...)
Hello everyone, I have used bash since last year and was amazed by its powerful features, but I only treated it as a prompt that makes doing things faster then......
Until this month I started to learn bash noscripting and started to get confused by some of its logic... for example the noscript below, I still did not get it...
https://preview.redd.it/pv61mddgpytb1.png?width=947&format=png&auto=webp&s=6e807609771071c9d52af5178f0262d6a7a8d113
(1) If originally the battery was greater than 30, when battery was becoming lower than 30 , it did not quit the loop and did not showing the message either.
(2) If it was lower than 30 when I ran this program, it will show up the warning message and quit the loop.
​
I've searched for some information on the internet saying that "if [ \]" and "if " different, but I'm still not clear about the concept...
I will be appreciate if someone can explain it to me...thanks
https://redd.it/176xs3b
@r_bash
Hello everyone, I have used bash since last year and was amazed by its powerful features, but I only treated it as a prompt that makes doing things faster then......
Until this month I started to learn bash noscripting and started to get confused by some of its logic... for example the noscript below, I still did not get it...
https://preview.redd.it/pv61mddgpytb1.png?width=947&format=png&auto=webp&s=6e807609771071c9d52af5178f0262d6a7a8d113
(1) If originally the battery was greater than 30, when battery was becoming lower than 30 , it did not quit the loop and did not showing the message either.
(2) If it was lower than 30 when I ran this program, it will show up the warning message and quit the loop.
​
I've searched for some information on the internet saying that "if [ \]" and "if " different, but I'm still not clear about the concept...
I will be appreciate if someone can explain it to me...thanks
https://redd.it/176xs3b
@r_bash