Package version is visible, but package not technically "Installed" from tar.gz.
If I try to extract a pre-compiled package from a tar.gz file to my system's /usr/local/bin and lib, I get the version of the package by doing <package_name> --version.
But I do not see it in the installed list when I do dpkg --list.
dpkg --status <package> says package not installed.
Am I missing something? Reminder that the tar.gz is pre-compiled.
https://redd.it/137xn0d
@r_bash
If I try to extract a pre-compiled package from a tar.gz file to my system's /usr/local/bin and lib, I get the version of the package by doing <package_name> --version.
But I do not see it in the installed list when I do dpkg --list.
dpkg --status <package> says package not installed.
Am I missing something? Reminder that the tar.gz is pre-compiled.
https://redd.it/137xn0d
@r_bash
Reddit
r/bash on Reddit: Package version is visible, but package not technically "Installed" from tar.gz.
Posted by u/Feeling-Character-31 - No votes and 1 comment
Need help debugging a noscript that runs a command given by parameter and stores stdout and stderr in variables
I am trying to make a function that will execute a command, store stdout and stderr in variables, check if the command errored or not, and then do something for each case. In this example I'm just echoing "success" or "failure".
This is the current state of the noscript:
https://redd.it/137zryq
@r_bash
I am trying to make a function that will execute a command, store stdout and stderr in variables, check if the command errored or not, and then do something for each case. In this example I'm just echoing "success" or "failure".
This is the current state of the noscript:
#! /bin/bash
execute_with_error_handling() {
step = $1
shift
# Execute the command passed as argument, store stdout and stderr in variables and capture the exit status
exec 3>&1 4>&2
output=$( { "$@" 2>&4 1>&3; echo $? > exit_status.tmp; } 2>&1 )
exec 3>&- 4>&-
# Separate stdout, stderr, and exit_status
stdout=$(echo "${output}" | grep -v '^stderr:')
stderr=$(echo "${output}" | grep '^stderr:' | sed 's/^stderr: //')
exit_status=$(cat exit_status.tmp && rm exit_status.tmp)
if [ "${exit_status}" -eq 0 ]; then
echo "success"
echo $stdout
echo $stderr
else
echo "fail"
echo $stdout
echo $stderr
fi
}
execute_with_error_handling "something that works" echo "hello world"
execute_with_error_handling "something that fails" false
https://redd.it/137zryq
@r_bash
Reddit
r/bash on Reddit: Need help debugging a noscript that runs a command given by parameter and stores stdout and stderr in variables
Posted by u/brubsabrubs - No votes and 1 comment
Comparing Float in if statement
I ran into a problem while comparing python version in my noscript, if anyone is familiar with this error please help
My noscript
Error i am getting
./2.bash: line 5: [: 3.11: syntax error: invalid arithmetic operator (error token is ".11")**
**./2.bash: line 7: [[: 3.11: syntax error: invalid arithmetic operator (error token is ".11")**
[https://redd.it/138it52
@r_bash
I ran into a problem while comparing python version in my noscript, if anyone is familiar with this error please help
My noscript
#!/bin/bash
PYTHON="/usr/bin/python3"
PYTHON_VERSION=$(${PYTHON} --version | grep -Po "(\d+\.)[^ .]+")
if [[ $PYTHON_VERSION -ge 3.11 ]] ; then
echo "python - ok"
elif [[ $PYTHON_VERSION -lt 3.11 ]] ; then
echo "lowest version"
fi
Error i am getting
./2.bash: line 5: [: 3.11: syntax error: invalid arithmetic operator (error token is ".11")**
**./2.bash: line 7: [[: 3.11: syntax error: invalid arithmetic operator (error token is ".11")**
[https://redd.it/138it52
@r_bash
Reddit
r/bash on Reddit: Comparing Float in if statement
Posted by u/hashtag_raunak - No votes and 6 comments
How to delete the last blank line in a .txt file?
Hi;
I’m working on a noscript that’s supposed to remove the white spaces and empty lines from a txt file. On a Macbook.
So far, I’ve been able to do that with sed an a regex pattern.
The issue is that it keeps the last blank line in place.
For example, once edited, I’d like my document to show:
and stop there.
Instead, I’m getting:
Would you know why that happens?
I’ve tried many variations of suggested stackoverflow “sed” solutions, but none of them has been helpful so far.
https://redd.it/1394kj1
@r_bash
Hi;
I’m working on a noscript that’s supposed to remove the white spaces and empty lines from a txt file. On a Macbook.
So far, I’ve been able to do that with sed an a regex pattern.
The issue is that it keeps the last blank line in place.
For example, once edited, I’d like my document to show:
- x
- y
- z
and stop there.
Instead, I’m getting:
- x
- y
- z
[blank line here]
Would you know why that happens?
I’ve tried many variations of suggested stackoverflow “sed” solutions, but none of them has been helpful so far.
https://redd.it/1394kj1
@r_bash
Replacing multiple spaces
Hi everyone.
So i have been trying to replace multiple (>2) whitspaces in a file with two dashes. --
I am trying this sed command. But it doesn't work.
Can anyone help?
Example
Expected out
Hi--Lokesh kumar--maxi
https://redd.it/139e3dr
@r_bash
Hi everyone.
So i have been trying to replace multiple (>2) whitspaces in a file with two dashes. --
I am trying this sed command. But it doesn't work.
sed`s/[ ][ ]*/\-\-/g`
Can anyone help?
Example
Hi Lokesh kumar maxi
Expected out
Hi--Lokesh kumar--maxi
https://redd.it/139e3dr
@r_bash
Reddit
r/bash on Reddit: Replacing multiple spaces
Posted by u/Lokeshwar916 - No votes and no comments
Finding the current cursor position in bash
The call for getting printed current row and col on screen are easy,(
So, having other things to spend my time on, after a little while, I came by these two links, that seem okay for terminals in linux.
This way uses the
The answer by Dennis Williamson in Stack Overlow post is more finicky but uses only bash, and, returns correct row/col positions for further use with ncurses.
https://redd.it/139hvju
@r_bash
The call for getting printed current row and col on screen are easy,(
echo -e "^]]6n"), but it is harder to stuff the values into variables, so you can actually use them.So, having other things to spend my time on, after a little while, I came by these two links, that seem okay for terminals in linux.
This way uses the
ncurses tput command, which you should install anyways for this. Stack-exchangeThe answer by Dennis Williamson in Stack Overlow post is more finicky but uses only bash, and, returns correct row/col positions for further use with ncurses.
https://redd.it/139hvju
@r_bash
Unix & Linux Stack Exchange
Get vertical cursor position
This might sound pretty weird, but I know how to set the vertical cursor position in Bash like this:
echo -e "\e[12H"
This moves the cursor to the 12th line (starting with 1).
So how do I get the
echo -e "\e[12H"
This moves the cursor to the 12th line (starting with 1).
So how do I get the
assign fields parsed via awk; delimiter
Bash 5.1 on Linux Mint 21.1
i need to decode filenames always following this structure: Part1_Part2_Part3.wav
The delimiter is an underscore.
With the code field=$(echo "$file" | awk 'BEGIN{FS="_"} {print $3}' )" i only be successful, if there is an underscore behind Part3. Right now i add an underscore to all the files for the code to work. Is there another way?
https://redd.it/139kbnn
@r_bash
Bash 5.1 on Linux Mint 21.1
i need to decode filenames always following this structure: Part1_Part2_Part3.wav
The delimiter is an underscore.
With the code field=$(echo "$file" | awk 'BEGIN{FS="_"} {print $3}' )" i only be successful, if there is an underscore behind Part3. Right now i add an underscore to all the files for the code to work. Is there another way?
https://redd.it/139kbnn
@r_bash
Reddit
r/bash on Reddit: assign fields parsed via awk; delimiter
Posted by u/slangbein - No votes and 1 comment
Creating a new variable from using grep on another variable
I am writing a noscript which enters a task into the taskwarrior app. The app response is "Created task number 114" (or any other number for that matter). I can catch that in a variable.
Now I want to use only the number (114) to use a a variable later (I can create a new task which is declared as dependent on task 114). According to what I have found already, this should work, but unfortunately does not:
Tasknumber=$(echo "$Response" | grep '[0-9\] {1,4}$')
when I echo $Tasknumber, it is empty.
Any tipps? Thank you
https://redd.it/139v7pb
@r_bash
I am writing a noscript which enters a task into the taskwarrior app. The app response is "Created task number 114" (or any other number for that matter). I can catch that in a variable.
Now I want to use only the number (114) to use a a variable later (I can create a new task which is declared as dependent on task 114). According to what I have found already, this should work, but unfortunately does not:
Tasknumber=$(echo "$Response" | grep '[0-9\] {1,4}$')
when I echo $Tasknumber, it is empty.
Any tipps? Thank you
https://redd.it/139v7pb
@r_bash
Reddit
r/bash on Reddit: Creating a new variable from using grep on another variable
Posted by u/spots_reddit - No votes and 1 comment
Are fractional seconds in HISTTIMEFORMAT possible?
As the noscript says I'm interested whether or not it's possible to specify fractional seconds.
I already tried:
It appears that it's not possible.
And I find that odd and dissatisfying, because I don't get "the issue" as why not.
That man page only says it must be in
https://redd.it/139wiy9
@r_bash
As the noscript says I'm interested whether or not it's possible to specify fractional seconds.
I already tried:
HISTTIMEFORMAT='%.3s '
HISTTIMEFORMAT='%s.%N '
HISTTIMEFORMAT='%s.%f '
It appears that it's not possible.
And I find that odd and dissatisfying, because I don't get "the issue" as why not.
That man page only says it must be in
strftime format. GNU date accepts %N and bash's HISTTIMEFORMAT doesn't.https://redd.it/139wiy9
@r_bash
Reddit
r/bash on Reddit: Are fractional seconds in HISTTIMEFORMAT possible?
Posted by u/PsychologicalOwl496 - No votes and 2 comments
How do i create a large text file crawler which crawls and finds keywords and condition quicker than usual grep awk considering the log file size as 10-20gb .gz file of text. Is there a way?
https://redd.it/13adoww
@r_bash
https://redd.it/13adoww
@r_bash
Reddit
r/bash on Reddit: How do i create a large text file crawler which crawls and finds keywords and condition quicker than usual grep…
Posted by u/UsedAd9359 - No votes and no comments
Is there a way to remove the background of dialog command? Currently its blue but I want it as terminal default or like black.
https://redd.it/13adkik
@r_bash
https://redd.it/13adkik
@r_bash
Reddit
r/bash on Reddit: Is there a way to remove the background of dialog command? Currently its blue but I want it as terminal default…
Posted by u/UsedAd9359 - No votes and no comments
Is there a way to use grep with wildcards?
Example
$file ./-* | grep "ASCII text" -w
./-file07: ASCII text
./-file09: Non-ISO extended-ASCII text, with no line terminators
I just want ./-file07. In a sql query it would look like
Select file from files where name like “ASCII%”
This would only return the files that names began with ASCII
Im assuming there is a way to accomplish this right?? Thanks
https://redd.it/13b2pmg
@r_bash
Example
$file ./-* | grep "ASCII text" -w
./-file07: ASCII text
./-file09: Non-ISO extended-ASCII text, with no line terminators
I just want ./-file07. In a sql query it would look like
Select file from files where name like “ASCII%”
This would only return the files that names began with ASCII
Im assuming there is a way to accomplish this right?? Thanks
https://redd.it/13b2pmg
@r_bash
Reddit
r/bash on Reddit: Is there a way to use grep with wildcards?
Posted by u/Tyrannosaurus_Sex90 - No votes and 1 comment
For overthewire bandit level 14 nc is used to send password to localhost, if its correct it sends back “Correct!” with the next levels password. I am trying to replicate this but cant.
Solution is here: https://mayadevbe.me/posts/overthewire/bandit/level15/
This is how I tried to replicate it… I opened 2 terminals. In one terminal I started listening for inputs on port 1234. If the input matches “password” I wanted to send back “Success” but I cannot figure out how to send the response back and display it on the client terminal
Server
nc -l -p 1234 | grep "password" | xargs -I {} echo "Success”
Client
nc localhost 1234
> password
this is able to recognize when password is sent but the message is printed out server side. How can I get it to print out on the client side???
Thank you.
https://redd.it/13b961r
@r_bash
Solution is here: https://mayadevbe.me/posts/overthewire/bandit/level15/
This is how I tried to replicate it… I opened 2 terminals. In one terminal I started listening for inputs on port 1234. If the input matches “password” I wanted to send back “Success” but I cannot figure out how to send the response back and display it on the client terminal
Server
nc -l -p 1234 | grep "password" | xargs -I {} echo "Success”
Client
nc localhost 1234
> password
this is able to recognize when password is sent but the message is printed out server side. How can I get it to print out on the client side???
Thank you.
https://redd.it/13b961r
@r_bash
MayADevBe Blog
OverTheWire Bandit Level 14 -> 15 - Walkthrough
A walkthrough of Level 14 -> 15 of the Bandit wargame from OverTheWire. - Netcat and first network communication.
Remove Text Outside margins?
So basically I have a decent collection of PDF/ePub files that I’d like to strip out the header and footer info, like page number, chapter etc etc. so I can pass it through a text to speech generator, is there a reasonable way to accomplish this in a bash noscript? Maybe parameters so I can define the area to keep ?
https://redd.it/13bacau
@r_bash
So basically I have a decent collection of PDF/ePub files that I’d like to strip out the header and footer info, like page number, chapter etc etc. so I can pass it through a text to speech generator, is there a reasonable way to accomplish this in a bash noscript? Maybe parameters so I can define the area to keep ?
https://redd.it/13bacau
@r_bash
Reddit
r/bash on Reddit: Remove Text Outside margins?
Posted by u/GlassBottleCokes - No votes and 2 comments
Need help use AWK if then in a noscript
Good evening (EDT)
I am trying to write a short noscript that returns the last word of a file. This is pretty easy:
#!/bin/bash
sudo apt update &>/home/user/.config/polybar/modules/apt &&
cat /home/user/.config/polybar/modules/apt | awk 'END{print $1}'
(The word at the end of the file is how many APT packages need updating)
However, when everything is up to date, the noscript returns "All" as that is the first word of the last line of the temp file created in line 2 of the noscript.
What is a good way to return the first word of the last line UNLESS that word is "All" in which case "0" (or some other phrase) is returned?
Thank you!
https://redd.it/13b8cj0
@r_bash
Good evening (EDT)
I am trying to write a short noscript that returns the last word of a file. This is pretty easy:
#!/bin/bash
sudo apt update &>/home/user/.config/polybar/modules/apt &&
cat /home/user/.config/polybar/modules/apt | awk 'END{print $1}'
(The word at the end of the file is how many APT packages need updating)
However, when everything is up to date, the noscript returns "All" as that is the first word of the last line of the temp file created in line 2 of the noscript.
What is a good way to return the first word of the last line UNLESS that word is "All" in which case "0" (or some other phrase) is returned?
Thank you!
https://redd.it/13b8cj0
@r_bash
Reddit
r/bash on Reddit: Need help use AWK if then in a noscript
Posted by u/HerefortheLAN - 1 vote and 2 comments
What happens if I do kill -TERM 0
I know sending TERM to 0 will send TERM to ALL the process in current process group but will the following cause infinite loop?
trap "kill -TERM 0" TERM
./ child_process
I am trying to figure out the behaviour of current process after sending kill -TERM 0
https://redd.it/13bphhw
@r_bash
I know sending TERM to 0 will send TERM to ALL the process in current process group but will the following cause infinite loop?
trap "kill -TERM 0" TERM
./ child_process
I am trying to figure out the behaviour of current process after sending kill -TERM 0
https://redd.it/13bphhw
@r_bash
Is it true that bash/sh (or shell languages in general) were first designed to be used by end users and not programmers?
I don't know where I heard or read this first but I can't find any good source on it, is it true that shell languages were first designed to be used by Unix end users in the 70s-90s who didn't know much about programming?
https://redd.it/13bxtlp
@r_bash
I don't know where I heard or read this first but I can't find any good source on it, is it true that shell languages were first designed to be used by Unix end users in the 70s-90s who didn't know much about programming?
https://redd.it/13bxtlp
@r_bash
Reddit
r/bash on Reddit: Is it true that bash/sh (or shell languages in general) were first designed to be used by end users and not programmers?
Posted by u/ED9898A - No votes and 1 comment
How to close all previously running gnome terminals, and start up new ones? pkill doestn work.
Hi, i would really appreciate some help with a simple noscript. I have an autonomous robot running on ROS (robot operating system).
My task right now is this:
1. I have 6-7 terminals running at all times. At a certain point of an automated process (robot coming to dock), I want to close all running terminals
2. Run specific commands to launch robot processes
I have tried using pkill to close all terminals but when I try to run commands after that, it doesnt work. Could you point me in the right direction?
​
Thanks
https://redd.it/13bwqwb
@r_bash
Hi, i would really appreciate some help with a simple noscript. I have an autonomous robot running on ROS (robot operating system).
My task right now is this:
1. I have 6-7 terminals running at all times. At a certain point of an automated process (robot coming to dock), I want to close all running terminals
2. Run specific commands to launch robot processes
I have tried using pkill to close all terminals but when I try to run commands after that, it doesnt work. Could you point me in the right direction?
​
Thanks
https://redd.it/13bwqwb
@r_bash
Reddit
r/bash on Reddit: How to close all previously running gnome terminals, and start up new ones? pkill doestn work.
Posted by u/shady_downforce - No votes and no comments
Help with referencing a variable and dealing with quotes, escapes, and braces?
These are the source folders in an rsync command. It works as-is but I can't figure out how to put this in a variable and then refer to the variable instead. All on one line, it's:
>/Users/$USER/Library/./Mobile\\ Documents/com\~apple\~{Pages,Numbers,Keynote}/ /Users/$USER/./Documents/Folder\\ name
I tried putting it in a variable as
>SOURCE= "/Users/$USER/Library/./Mobile Documents/com\~apple\~{Pages,Numbers,Keynote}/ /Users/$USER/./Documents/Developer/Folder name"
And then referring to
>"${SOURCE}"
I also tried the variable reference without curly braces and without quotes, and adding an escape before the spaces in the variable. Nothing I've tried works. I get an error message that the folder can't be found. The error quotes both folder references together. I think my issue is properly handling spaces when inside a quote that defines a variable, and maybe the braces when in a variable.
My underlying goal is to have a variable that includes all the source folders, and then just refer to the variable in the rsync command.
https://redd.it/13c2br3
@r_bash
These are the source folders in an rsync command. It works as-is but I can't figure out how to put this in a variable and then refer to the variable instead. All on one line, it's:
>/Users/$USER/Library/./Mobile\\ Documents/com\~apple\~{Pages,Numbers,Keynote}/ /Users/$USER/./Documents/Folder\\ name
I tried putting it in a variable as
>SOURCE= "/Users/$USER/Library/./Mobile Documents/com\~apple\~{Pages,Numbers,Keynote}/ /Users/$USER/./Documents/Developer/Folder name"
And then referring to
>"${SOURCE}"
I also tried the variable reference without curly braces and without quotes, and adding an escape before the spaces in the variable. Nothing I've tried works. I get an error message that the folder can't be found. The error quotes both folder references together. I think my issue is properly handling spaces when inside a quote that defines a variable, and maybe the braces when in a variable.
My underlying goal is to have a variable that includes all the source folders, and then just refer to the variable in the rsync command.
https://redd.it/13c2br3
@r_bash
Reddit
r/bash on Reddit: Help with referencing a variable and dealing with quotes, escapes, and braces?
Posted by u/limpingrobot - No votes and 3 comments