Why is trap handler not invoked immediately in this noscript
#!/bin/bash
cleanup() {
echo "Received SIGTERM signal. Cleaning up..."
exit 1
}
echo "Spawning child process..."
trap cleanup SIGTERM
sleep 10
echo $?
When I issue a SIGTERM after 2-3 seconds after invoking this process the cleanup is called AFTER 10 seconds. Shoulnd't the trap handler invoke immediately?
https://redd.it/12jqard
@r_bash
#!/bin/bash
cleanup() {
echo "Received SIGTERM signal. Cleaning up..."
exit 1
}
echo "Spawning child process..."
trap cleanup SIGTERM
sleep 10
echo $?
When I issue a SIGTERM after 2-3 seconds after invoking this process the cleanup is called AFTER 10 seconds. Shoulnd't the trap handler invoke immediately?
https://redd.it/12jqard
@r_bash
Reddit
r/bash on Reddit: Why is trap handler not invoked immediately in this noscript
Posted by u/ForeignCabinet2916 - No votes and 2 comments
bashelim collates a noscript with its sources (nested), and sends the result to stdout
Sometimes it is nice to collate all the noscripts that is at play,
in order to make it easier to inspect, or to share with someone
maybe after some final editing.
This noscript, is an adaption of the `soelim` noscript for collating
`troff` sources, for bash, it understands `.` and `source`, and also
nested files, and that cycles of nested files are bad!
This version doesn't read the path and looks for sources any other
place than in the current folder, tildes are expanded into the home-
folder however.
#!/bin/awk -f
# McUsr 2023 Mostly stolen from Jon Bently's m1.awk
# Vim licence
# bashelim instead of soelim V.0.0.0
# Collates the bashcript presented on the command line
# with all sourced files, for debugging purposes.
# Tildexpands any paths.but doesn't look through the path
# to find files without pathname besides the current folder.
BEGIN {
RS="\n"
hp=ENVIRON["HOME"]
}
function error(s) {
print "m1 error: " s | "cat 1>&2"; exit 1
}
function dofile(fname, savefile, savebuffer, newstring) {
if (fname in activefiles)
error("recursively reading file: " fname)
activefiles[fname] = 1
savefile = file; file = fname
savebuffer = buffer; buffer = ""
while (readline() != EOF) {
if (/^[ \t]*source[ \t]/) {
if (NF != 2) error("bad source line")
sub("~",hp,$2)
dofile(dosubs($2))
} else if (/^[ \t]*\.[ \t]/) {
if (NF != 2) error("bad source line")
sub("~",hp,$2)
dofile(dosubs($2))
} else
print $0
}
close(fname)
delete activefiles[fname]
file = savefile
buffer = savebuffer
}
# readline
#Put next input line into global string "buffer".
#Return "EOF" or "" (null string).
function readline( i, status) {
status = ""
if (buffer != "") {
i = index(buffer, "\n")
$0 = substr(buffer, 1, i-1)
buffer = substr(buffer, i+1)
} else {
# Hume: special case for non v10: if (file == "/dev/stdin")
if (getline <file <= 0)
status = EOF
}
# Hack: allow @Mname at start of line w/o closing @
if ($0 ~ /^@[A-Z][a-zA-Z0-9]*[ \t]*$/)
sub(/[ \t]*$/, "@")
return status
}
function dosubs(s, l, r, i, m) {
if (index(s, "@") == 0)
return s
l = "" # Left of current pos; ready for output
r = s # Right of current; unexamined at this time
while ((i = index(r, "@")) != 0) {
l = l substr(r, 1, i-1)
r = substr(r, i+1) # Currently scanning @
i = index(r, "@")
if (i == 0) {
l = l "@"
break
}
m = substr(r, 1, i-1)
r = substr(r, i+1)
if (m in symtab) {
r = symtab[m] r
} else {
l = l "@" m
r = "@" r
}
}
return l r
}
BEGIN {
EOF = "EOF"
if (ARGC == 1)
dofile("/dev/stdin")
else if (ARGC >= 2) {
for (i = 1; i < ARGC; i++)
dofile(ARGV[i])
} else
error("usage: m1 [fname...]")
}
# This noscript is excavated out of the M1.awk macro processor by Jon L. Bentley.
#M1 was documented in the 1997 sedawk book by Dale Dougherty & Arnold Robbins (ISBN 1-56592-225-5)
#but may have been written earlier.
#.P
# This noscript was adapted from the 1997 sedawk book by Dale Dougherty & Arnold Robbins (ISBN 1-56592-225-5)
# 131.191.66.141:8181/UNIX_BS/sedawk/examples/ch13/m1.pdf (download from
#<a href="http://lawker.googlecode.com/svn/fridge/share/pdf/m1.pdf">LAWKER</a>).
# Author Jon L. Bentley. (Of "Programming Pearls" fame.)
https://redd.it/12jv83a
@r_bash
Sometimes it is nice to collate all the noscripts that is at play,
in order to make it easier to inspect, or to share with someone
maybe after some final editing.
This noscript, is an adaption of the `soelim` noscript for collating
`troff` sources, for bash, it understands `.` and `source`, and also
nested files, and that cycles of nested files are bad!
This version doesn't read the path and looks for sources any other
place than in the current folder, tildes are expanded into the home-
folder however.
#!/bin/awk -f
# McUsr 2023 Mostly stolen from Jon Bently's m1.awk
# Vim licence
# bashelim instead of soelim V.0.0.0
# Collates the bashcript presented on the command line
# with all sourced files, for debugging purposes.
# Tildexpands any paths.but doesn't look through the path
# to find files without pathname besides the current folder.
BEGIN {
RS="\n"
hp=ENVIRON["HOME"]
}
function error(s) {
print "m1 error: " s | "cat 1>&2"; exit 1
}
function dofile(fname, savefile, savebuffer, newstring) {
if (fname in activefiles)
error("recursively reading file: " fname)
activefiles[fname] = 1
savefile = file; file = fname
savebuffer = buffer; buffer = ""
while (readline() != EOF) {
if (/^[ \t]*source[ \t]/) {
if (NF != 2) error("bad source line")
sub("~",hp,$2)
dofile(dosubs($2))
} else if (/^[ \t]*\.[ \t]/) {
if (NF != 2) error("bad source line")
sub("~",hp,$2)
dofile(dosubs($2))
} else
print $0
}
close(fname)
delete activefiles[fname]
file = savefile
buffer = savebuffer
}
# readline
#Put next input line into global string "buffer".
#Return "EOF" or "" (null string).
function readline( i, status) {
status = ""
if (buffer != "") {
i = index(buffer, "\n")
$0 = substr(buffer, 1, i-1)
buffer = substr(buffer, i+1)
} else {
# Hume: special case for non v10: if (file == "/dev/stdin")
if (getline <file <= 0)
status = EOF
}
# Hack: allow @Mname at start of line w/o closing @
if ($0 ~ /^@[A-Z][a-zA-Z0-9]*[ \t]*$/)
sub(/[ \t]*$/, "@")
return status
}
function dosubs(s, l, r, i, m) {
if (index(s, "@") == 0)
return s
l = "" # Left of current pos; ready for output
r = s # Right of current; unexamined at this time
while ((i = index(r, "@")) != 0) {
l = l substr(r, 1, i-1)
r = substr(r, i+1) # Currently scanning @
i = index(r, "@")
if (i == 0) {
l = l "@"
break
}
m = substr(r, 1, i-1)
r = substr(r, i+1)
if (m in symtab) {
r = symtab[m] r
} else {
l = l "@" m
r = "@" r
}
}
return l r
}
BEGIN {
EOF = "EOF"
if (ARGC == 1)
dofile("/dev/stdin")
else if (ARGC >= 2) {
for (i = 1; i < ARGC; i++)
dofile(ARGV[i])
} else
error("usage: m1 [fname...]")
}
# This noscript is excavated out of the M1.awk macro processor by Jon L. Bentley.
#M1 was documented in the 1997 sedawk book by Dale Dougherty & Arnold Robbins (ISBN 1-56592-225-5)
#but may have been written earlier.
#.P
# This noscript was adapted from the 1997 sedawk book by Dale Dougherty & Arnold Robbins (ISBN 1-56592-225-5)
# 131.191.66.141:8181/UNIX_BS/sedawk/examples/ch13/m1.pdf (download from
#<a href="http://lawker.googlecode.com/svn/fridge/share/pdf/m1.pdf">LAWKER</a>).
# Author Jon L. Bentley. (Of "Programming Pearls" fame.)
https://redd.it/12jv83a
@r_bash
New release of bkt, a subprocess caching utility
Hi all, I recently cut a new release of `bkt` with some additional functionality. Notably, it's now possible to include a file's last-modified time in the cache key, thereby invalidating the cache if the file changes.
Wait, what is
Another way I use
$ curl http://some.api/data/a | jq '.foo'
$ curl http://some.api/data/a | jq '.foo.bar'
$ curl http://some.api/data/b | jq '.foo.bar.baz'
Which is obviously wasteful and slow. You could write the output to a file and then pipe that to
Instead, using `bkt` ensures each request is only sent once and all subsequent calls return locally cached results:
$ bkt --ttl=1d -- curl http://some.api/data/a | jq '.foo'
$ bkt --ttl=1d -- curl http://some.api/data/a | jq '.foo.bar'
$ bkt --ttl=1d -- curl http://some.api/data/b | jq '.foo.bar.baz'
If you haven't used it before give it a spin! If you find it useful please share how you're using `bkt` so others can benefit :)
https://redd.it/12ke9i3
@r_bash
Hi all, I recently cut a new release of `bkt` with some additional functionality. Notably, it's now possible to include a file's last-modified time in the cache key, thereby invalidating the cache if the file changes.
Wait, what is
bkt?bkt is a subprocess caching utility you can use to persist a command's output so that subsequent invocations are fast. As an example, I use bkt heavily in my shell prompt to speed up the information it displays.Another way I use
bkt often is to simplify and speed up iterating on command pipelines that are slow to run. For example, if you're using jq to play around with a JSON response you might do something like this:$ curl http://some.api/data/a | jq '.foo'
$ curl http://some.api/data/a | jq '.foo.bar'
$ curl http://some.api/data/b | jq '.foo.bar.baz'
Which is obviously wasteful and slow. You could write the output to a file and then pipe that to
jq, but you often end up juggling multiple response files and it get's tedious quickly.Instead, using `bkt` ensures each request is only sent once and all subsequent calls return locally cached results:
$ bkt --ttl=1d -- curl http://some.api/data/a | jq '.foo'
$ bkt --ttl=1d -- curl http://some.api/data/a | jq '.foo.bar'
$ bkt --ttl=1d -- curl http://some.api/data/b | jq '.foo.bar.baz'
If you haven't used it before give it a spin! If you find it useful please share how you're using `bkt` so others can benefit :)
https://redd.it/12ke9i3
@r_bash
GitHub
Release 0.6.0 · dimo414/bkt
What's Changed
Support environment variables BKT_TTL, BKT_SCOPE, and BKT_CACHE_DIR as alternatives for flags --ttl, --scope, and --cache-dir, respectively (#15).
Added support for keying the c...
Support environment variables BKT_TTL, BKT_SCOPE, and BKT_CACHE_DIR as alternatives for flags --ttl, --scope, and --cache-dir, respectively (#15).
Added support for keying the c...
bash-hackers.org is now a parking domain
Hi,
i have just noticed bash-hackers.org is now a parking domain, narf. Does anybody have some insights what happened and if there is some new place for this very much appreciated resource?
> whois bash-hackers.org
Domain Name: bash-hackers.org
Registry Domain ID: 660cea3369e54dbe9ca037d2d1925eaa-LROR
Registrar WHOIS Server: http://whois.ionos.com
Registrar URL: https://www.ionos.com
Updated Date: 2023-04-13T05:09:00Z
Creation Date: 2007-04-13T04:46:21Z
Registry Expiry Date: 2024-04-13T04:46:21Z
Registrar: IONOS SE
https://redd.it/12klulf
@r_bash
Hi,
i have just noticed bash-hackers.org is now a parking domain, narf. Does anybody have some insights what happened and if there is some new place for this very much appreciated resource?
> whois bash-hackers.org
Domain Name: bash-hackers.org
Registry Domain ID: 660cea3369e54dbe9ca037d2d1925eaa-LROR
Registrar WHOIS Server: http://whois.ionos.com
Registrar URL: https://www.ionos.com
Updated Date: 2023-04-13T05:09:00Z
Creation Date: 2007-04-13T04:46:21Z
Registry Expiry Date: 2024-04-13T04:46:21Z
Registrar: IONOS SE
https://redd.it/12klulf
@r_bash
Passing a command with double quotes to a function
Hi, I'm writing a noscript to create thumbnails and see them as preview for different types of files.
The problematic part is with passing to
Does somebody knows if I'm passing those commands to
https://redd.it/12kwbq8
@r_bash
Hi, I'm writing a noscript to create thumbnails and see them as preview for different types of files.
#!/bin/sh
file="$1"
w="$2"
h="$3"
x="$4"
y="$5"
mkdir -p '/tmp/lf'
cache() {
cache="/tmp/lf/$(echo "$file" | tr '/' '%')"
[ ! -f "$cache" ] && "$@" && echo '[SUCCESS]'
kitten icat --silent --transfer-mode file --stdin no --place "${w}x${h}@${x}x${y}" "$cache" < /dev/null > /dev/tty
}
case "$(file -Lb --mime-type "$file")" in
application/json) jq -C "$file" ;;
application/octet-stream|video/*)
cache ffmpegthumbnailer -i "$file" -o "$cache.jpg" -s 0 -q 4 ;;
application/pdf)
cache pdftoppm -singlefile -jpeg "$file" "$cache" ;;
application/x-7z-compressed) 7z l -p "$file" ;;
application/x-tar) tar rf "$1" ;;
application/x-rar) unrar lt -p- "$file" ;;
application/zip) unzip -l "$file" ;;
image/*) kitten icat --silent --transfer-mode file --stdin no --place "${w}x${h}@${x}x${y}" "$file" < /dev/null > /dev/tty ;;
text/*) cat "$file" ;;
*) echo '----- File Type Classification -----' && file -Lb "$file" ;;
esac
exit 1
The problematic part is with passing to
cache the command to create a thumbnail like in the case of application/pdf. I see the message [SUCCESS] on screen but the files doesn't get created at all. In the case of video/* I don't even see the message on screen.Does somebody knows if I'm passing those commands to
cache the wrong way? (Also if there is any other suggestion on style please tell me)https://redd.it/12kwbq8
@r_bash
Reddit
r/bash on Reddit: Passing a command with double quotes to a function
Posted by u/sicr0 - No votes and 4 comments
Brackets in sh noscript.
Hi!
I can't understand the code some noscript added to my rc.local when setting up vpn.
what are the "()" brackets for and why adding "&" at the end of the block? Wouldn't sh go line by line anyway? Rest of the code are clear to me. Could you clarify it for me? googling bash/sh brackets is like looking for a needle in the haystack.
https://redd.it/12kyyqt
@r_bash
Hi!
I can't understand the code some noscript added to my rc.local when setting up vpn.
(sleep 15service ipsec restartservice xl2tpd restartecho 1 > /proc/sys/net/ipv4/ip_forward)&what are the "()" brackets for and why adding "&" at the end of the block? Wouldn't sh go line by line anyway? Rest of the code are clear to me. Could you clarify it for me? googling bash/sh brackets is like looking for a needle in the haystack.
https://redd.it/12kyyqt
@r_bash
Reddit
r/bash on Reddit: Brackets in sh noscript.
Posted by u/arturkwiatkowski - No votes and 2 comments
What happened with wiki.bash-hackers.org?
This site was a great guide for me, does anyone know what happened?, today I tried to check the page and it seems to be dead 😢
https://redd.it/12lmqoy
@r_bash
This site was a great guide for me, does anyone know what happened?, today I tried to check the page and it seems to be dead 😢
https://redd.it/12lmqoy
@r_bash
Reddit
r/bash on Reddit: What happened with wiki.bash-hackers.org?
Posted by u/urely - No votes and 2 comments
Need help as an absolute beginner on directories and files
Hi everyone. I have a class this semester which requires me to work with bash. We have a homework and unfortunately my course does not provide any helpful infos on how bash works. Here is my homework
Consider the following output from /usr/bin/tree -p | sed -E "s/(\\[d?)([rxw-\]+)/\\1/g":
.
|- [d\] bars
| |- [d\] baz
| | |- [\] corge
| |- [\] quuz
|- [d\] corge
| |- [d\] grault
| |- [d\] garply
| | |- [\] version
| |- [\] partitions
|- [d\] foo
| |- [\] quux
|- [\] fstab
|- [\]qux
|- [\] rumo
6 directories, 8 files
Create the same structure consisting of 6 directories and 8 files using only shell commands. Give all the commands to solve this task in the correct order. For the version, partitions, and fstab files, use the appropriate /proc/version, /proc/partitions, and /etc/fstab files. All other files should be empty.
From all the research i have done on the internet i came up with something like
mkdir root_.
mkdir root_./bar
mkdir root_./bar/baz
mkdir root_./corge
mkdir root_./corge/grault
mkdir root_./corge/grault/graply
mkdir root_./foo
touch root_./baz/corge.txt
touch root_./bar/quuz.txt
... and so on
Am I on the right path here? It could be compeletly different than what they are asking. Would be amazing if i could learn what am i supposed to do and maybe what to study.
All helps are appreciated thank you!
https://redd.it/12lrj2o
@r_bash
Hi everyone. I have a class this semester which requires me to work with bash. We have a homework and unfortunately my course does not provide any helpful infos on how bash works. Here is my homework
Consider the following output from /usr/bin/tree -p | sed -E "s/(\\[d?)([rxw-\]+)/\\1/g":
.
|- [d\] bars
| |- [d\] baz
| | |- [\] corge
| |- [\] quuz
|- [d\] corge
| |- [d\] grault
| |- [d\] garply
| | |- [\] version
| |- [\] partitions
|- [d\] foo
| |- [\] quux
|- [\] fstab
|- [\]qux
|- [\] rumo
6 directories, 8 files
Create the same structure consisting of 6 directories and 8 files using only shell commands. Give all the commands to solve this task in the correct order. For the version, partitions, and fstab files, use the appropriate /proc/version, /proc/partitions, and /etc/fstab files. All other files should be empty.
From all the research i have done on the internet i came up with something like
mkdir root_.
mkdir root_./bar
mkdir root_./bar/baz
mkdir root_./corge
mkdir root_./corge/grault
mkdir root_./corge/grault/graply
mkdir root_./foo
touch root_./baz/corge.txt
touch root_./bar/quuz.txt
... and so on
Am I on the right path here? It could be compeletly different than what they are asking. Would be amazing if i could learn what am i supposed to do and maybe what to study.
All helps are appreciated thank you!
https://redd.it/12lrj2o
@r_bash
Reddit
r/bash on Reddit: Need help as an absolute beginner on directories and files
Posted by u/StarsAreCute - No votes and no comments
Keyboard Shortcut won't execute noscripts and commands which are easily executable on terminal.
So, I installed a package called pix2tex. I wrote a noscript to run it and there also was a pre-written noscript which would launch a window as you can see here in this video
However, though the noscripts and commands run perfectly fine on terminal, they won't run when they are called with a custom shortcut that I assigned them in keyboard settings.
I recorded another video to demonstrate this issue. The noscript which is being executed is
Pix2tex, takes the screenshot, a.png and converts into latex. It's saved in a.tex and then it's copied. Unfortunately, when I try it with keyboard shortcut, it won't even be saved in a.tex (but it will be for terminal executed noscript).
~Edit: I do want to know the answer for future purposes, but for now anyway to run
https://redd.it/12lv6hs
@r_bash
So, I installed a package called pix2tex. I wrote a noscript to run it and there also was a pre-written noscript which would launch a window as you can see here in this video
However, though the noscripts and commands run perfectly fine on terminal, they won't run when they are called with a custom shortcut that I assigned them in keyboard settings.
I recorded another video to demonstrate this issue. The noscript which is being executed is
#!/bin/bash
xfce4-screenshooter --region --save /home/bob/Pictures/Screenshots/a.png
#only the xfce4-screenshooter command would be executed
pix2tex /home/bob/Pictures/Screenshots/a.png | sed 's/.*: //' > /home/bob/Pictures/Screenshots/a.tex
xclip -selection clipboard /home/bob/Pictures/Screenshots/a.tex
exit 0
Pix2tex, takes the screenshot, a.png and converts into latex. It's saved in a.tex and then it's copied. Unfortunately, when I try it with keyboard shortcut, it won't even be saved in a.tex (but it will be for terminal executed noscript).
~Edit: I do want to know the answer for future purposes, but for now anyway to run
latexocr gui without actually having to open the terminal would suffice, is there a way to use a shortcut to do the same job as I am doing in the first video?~https://redd.it/12lv6hs
@r_bash
Imgur
Discover the magic of the internet at Imgur, a community powered entertainment destination. Lift your spirits with funny jokes, trending memes, entertaining gifs, inspiring stories, viral videos, and so much more from users.
Is it possible to make zsh look like GitBash without appealing to OhMyZsh?
Hi everyone!
Nothing to add to the noscript, it speaks by itself, but to give you as much informations as possible I tell you what I did!
So, I recently switched to Mac. I'm studying web development and until now I used GitBash for windows. I immediately realized that zsh style was pretty different so I tried to modify it to make it look as close as possible like GitBash. I created a .zshrc file in my home directory and with vscode I did the following modifications PS1="%F{green}%n@%m%f %F{yellow}%1\~%f $ "
The problem is that there is a lot of stuff that I'd like to modify but I wasn't still able to figure out how yet. These are the main things that I'd like to achieve:
\-When I do 'ls' the directories are not listed in blue with the '/' symbol. I have to 'ls -F' to identify them as a directories (and of course they still miss the color).
\-I didn't do anything regarding git yet but I'd like to have the branch names between brackets and coloured in blue
\-In git bash I had the whole paths listed. For example I had \~/one/two/current-directory. Now I just have the current-directory listed. I have to 'pwd' to see the whole path.
\-Finally, in GitBash the prompt $ started in a new line.
I looked online and some people suggest ohmyzsh. I'd like to achieve these results with out it. I also did 'man ls' to see what it says about colours. It talks about CLICOLOR and LSCOLORS but I wasn't able to understand how to apply them to get the result yet.
Could you guys help me?
Thank you!
https://redd.it/12lz3kb
@r_bash
Hi everyone!
Nothing to add to the noscript, it speaks by itself, but to give you as much informations as possible I tell you what I did!
So, I recently switched to Mac. I'm studying web development and until now I used GitBash for windows. I immediately realized that zsh style was pretty different so I tried to modify it to make it look as close as possible like GitBash. I created a .zshrc file in my home directory and with vscode I did the following modifications PS1="%F{green}%n@%m%f %F{yellow}%1\~%f $ "
The problem is that there is a lot of stuff that I'd like to modify but I wasn't still able to figure out how yet. These are the main things that I'd like to achieve:
\-When I do 'ls' the directories are not listed in blue with the '/' symbol. I have to 'ls -F' to identify them as a directories (and of course they still miss the color).
\-I didn't do anything regarding git yet but I'd like to have the branch names between brackets and coloured in blue
\-In git bash I had the whole paths listed. For example I had \~/one/two/current-directory. Now I just have the current-directory listed. I have to 'pwd' to see the whole path.
\-Finally, in GitBash the prompt $ started in a new line.
I looked online and some people suggest ohmyzsh. I'd like to achieve these results with out it. I also did 'man ls' to see what it says about colours. It talks about CLICOLOR and LSCOLORS but I wasn't able to understand how to apply them to get the result yet.
Could you guys help me?
Thank you!
https://redd.it/12lz3kb
@r_bash
Reddit
r/bash on Reddit: Is it possible to make zsh look like GitBash without appealing to OhMyZsh?
Posted by u/91Flavio91 - No votes and 4 comments
a Bash noscript to eliminate lines in a delimited text file
Hello !
I have a file in a format like this, but bigger:
0.5 00000 aaaaa K 00000 aaaaaaa
0.5 11111 bbbbb P 11111 bbbbbbb
0.5 22222 ccccc F 22222 ccccccc
0.02 33333 ddddd G 33333 ddddddd
0.01 44444 eeeee S 44444 eeeeeee
0.01 55555 fffff S1 55555 fffffff
0.5 66666 ggggg G 66666 ggggggg
0.5 77777 hhhhh S 77777 hhhhhhh
I want to write a Bash noscript, that enters the file, and looks for a line that has G in the fourth column, if it's the case, it returns to the first column of that line and compares it to 0,04. If it's lower, the line should be deleted.
If a line that contains G is deleted, the noscript should look for the lines under, if they contain S or S1, or S2 they should be deleted also if they contain anything except that, no deletion is needed.
For that input, I should have an output like this:
0.5 00000 aaaaa K 00000 aaaaaaa
0.5 11111 bbbbb P 11111 bbbbbbb
0.5 22222 ccccc F 22222 ccccccc
0.5 66666 ggggg G 66666 ggggggg
0.5 77777 hhhhh S 77777 hhhhhhh
Thanks in advance! Have a good day.
https://redd.it/12lzfos
@r_bash
Hello !
I have a file in a format like this, but bigger:
0.5 00000 aaaaa K 00000 aaaaaaa
0.5 11111 bbbbb P 11111 bbbbbbb
0.5 22222 ccccc F 22222 ccccccc
0.02 33333 ddddd G 33333 ddddddd
0.01 44444 eeeee S 44444 eeeeeee
0.01 55555 fffff S1 55555 fffffff
0.5 66666 ggggg G 66666 ggggggg
0.5 77777 hhhhh S 77777 hhhhhhh
I want to write a Bash noscript, that enters the file, and looks for a line that has G in the fourth column, if it's the case, it returns to the first column of that line and compares it to 0,04. If it's lower, the line should be deleted.
If a line that contains G is deleted, the noscript should look for the lines under, if they contain S or S1, or S2 they should be deleted also if they contain anything except that, no deletion is needed.
For that input, I should have an output like this:
0.5 00000 aaaaa K 00000 aaaaaaa
0.5 11111 bbbbb P 11111 bbbbbbb
0.5 22222 ccccc F 22222 ccccccc
0.5 66666 ggggg G 66666 ggggggg
0.5 77777 hhhhh S 77777 hhhhhhh
Thanks in advance! Have a good day.
https://redd.it/12lzfos
@r_bash
Reddit
r/bash on Reddit: a Bash noscript to eliminate lines in a delimited text file
Posted by u/Quick_Repeat7033 - No votes and 3 comments
A new, unprecedented approach to the command line
https://asciinema.org/a/577630
https://redd.it/12m6fan
@r_bash
https://asciinema.org/a/577630
https://redd.it/12m6fan
@r_bash
asciinema.org
A novel approach to a merged mc/pure-shell like command line
A new approach to the command line: - it's a merge of Midnight Commander and command line, - … because everything is panelized, greppable and remembered, - you enter commands like ls, mv, cp, cat a...
How do I use double quotes in a remote ssh this way?
Normally I would set the today variable like this:
today="$(date +'%m-%d-%Y %H:%M:%S')"
Since I'm doing it on a remote server I am doing it this way:
ssh -T root@192.168.1.4 << EOL
today=\$(date +'%m-%d-%Y %H:%M:%S')
echo "\$today"
EOL
But what if I wanted to use the double quotes like normal? How would I do that remotely?
https://redd.it/12m9e3x
@r_bash
Normally I would set the today variable like this:
today="$(date +'%m-%d-%Y %H:%M:%S')"
Since I'm doing it on a remote server I am doing it this way:
ssh -T root@192.168.1.4 << EOL
today=\$(date +'%m-%d-%Y %H:%M:%S')
echo "\$today"
EOL
But what if I wanted to use the double quotes like normal? How would I do that remotely?
https://redd.it/12m9e3x
@r_bash
Reddit
r/bash on Reddit: How do I use double quotes in a remote ssh this way?
Posted by u/ztrz55 - No votes and no comments
quick question
Hello, I am making a noscript that installs and configures a bunch of stuff and I am having a problem with an EOF statement in a function. I am not sure if it works but VsCode and ShellCheck have both flagged it.
Code:
#adds desktop entries for WM's
dotdesktop () {
cat << EOF > /usr/share/xsessions/qtile.desktop
Desktop Entry
Name=Qtile
Comment=Qtile Window Manager
Exec=qtile start
Type=Application
Keywords=wm;tiling
EOF
cat << PIG > /usr/share/wayland-sessions/hypr.desktop
Desktop Entry
Name=Hyprland
Comment=Hyprland Window Manager
Exec=exec Hyprland
Type=Application
Keywords=wm;tiling;wayland
PIG
}
the errors are :
Couldn't parse this here document. Fix to allow more checks.
Remove indentation before end token (or use <<- and indent with tabs).
https://redd.it/12mn1l9
@r_bash
Hello, I am making a noscript that installs and configures a bunch of stuff and I am having a problem with an EOF statement in a function. I am not sure if it works but VsCode and ShellCheck have both flagged it.
Code:
#adds desktop entries for WM's
dotdesktop () {
cat << EOF > /usr/share/xsessions/qtile.desktop
Desktop Entry
Name=Qtile
Comment=Qtile Window Manager
Exec=qtile start
Type=Application
Keywords=wm;tiling
EOF
cat << PIG > /usr/share/wayland-sessions/hypr.desktop
Desktop Entry
Name=Hyprland
Comment=Hyprland Window Manager
Exec=exec Hyprland
Type=Application
Keywords=wm;tiling;wayland
PIG
}
the errors are :
Couldn't parse this here document. Fix to allow more checks.
Remove indentation before end token (or use <<- and indent with tabs).
https://redd.it/12mn1l9
@r_bash
Reddit
r/bash on Reddit: quick question
Posted by u/04AE - No votes and 3 comments
Need help filtering the output after phrase "Only Texts:"
[SOLVED]
Edit:
#!/bin/bash
xfce4-screenshooter --region --save /home/$USER/"formula.jpg"
p2t predict -i ./formula.jpg > ./output 2>&1
sed -n '/Only texts:/,$p' /home/bob/output | grep -v 'Only te>
`This worked`
I wrote a noscript to execute a command and only get part of the output return out of it. But I failed, Now I need your help to make the noscript return output which is after the string "Only Texts:".
The Script I used it [ChatGPT helped with the selection part]
#!/bin/bash
xfce4-screenshooter --region --save /home/$USER/Pictures/Screenshots/"formula.jpg"
output=$(p2t predict -i ./formula.jpg)
out=$(echo "$output" | grep -oP 'Only texts:.*?\$\$')
echo "${out:12}"
The output I recieve if I echo `output` is
```
$ ./pic2text
[INFO 2023-04-15 11:09:48,368 select_device:104] YOLOv7 🚀 2023-4-14 torch 2.0.0+cu117 CPU
[INFO 2023-04-15 11:09:48,368 __init__:161] Use model: /home/bob/.cnstd/1.2/analysis/mfd-yolov7_tiny.pt
[INFO 2023-04-15 11:09:48,544 __init__:597]
[INFO 2023-04-15 11:09:48,682 _get_model:178] use model: /home/bob/.cnocr/2.2/densenet_lite_136-fc/cnocr-v2.2-densenet_lite_136-fc-epoch=039-complete_match_epoch=0.8597-model.onnx
[INFO 2023-04-15 11:09:48,713 _assert_and_prepare_model_files:135] use model: /home/bob/.cnstd/1.2/ppocr/ch_PP-OCRv3_det_infer.onnx
[INFO 2023-04-15 11:09:48,760 _assert_and_prepare_model_files:110] use model: /home/bob/.cnocr/2.2/ppocr/en_PP-OCRv3_rec_infer.onnx
[INFO 2023-04-15 11:09:48,825 _assert_and_prepare_model_files:135] use model: /home/bob/.cnstd/1.2/ppocr/en_PP-OCRv3_det_infer.onnx
[INFO 2023-04-15 11:09:48,866 download_checkpoints:50] use model weights.pth from path /home/bob/.pix2text/formular
[INFO 2023-04-15 11:09:48,866 download_checkpoints:50] use model image_resizer.pth from path /home/bob/.pix2text/formular
[WARNING 2023-04-15 11:09:49,419 _showwarnmsg:109] /home/bob/.local/lib/python3.9/site-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3483.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
[INFO 2023-04-15 11:09:49,422 _analyze_one:338] Done. (68.7ms) Inference, (0.6ms) NMS
[INFO 2023-04-15 11:09:50,266 predict:119] In image: ./formula.jpg
Outs:
[{'position': array([[ 8, 15],
[ 459, 15],
[ 459, 110],
[ 8, 110]]),
'text': '$$\n'
'\\operatorname{d}={\\sqrt{\\left(x_{2}-\\chi_{3}\\right)^{2}+\\left(y_{2}-\\mathbf{y}_{1}\\right)^{2}}}\n'
'$$',
'type': 'isolated'}]
Only texts:
$$
\operatorname{d}={\sqrt{\left(x_{2}-\chi_{3}\right)^{2}+\left(y_{2}-\mathbf{y}_{1}\right)^{2}}}
$$
output
```
All, I want is (stuff after Only texts:)
```
$$
\operatorname{d}={\sqrt{\left(x_{2}-\chi_{3}\right)^{2}+\left(y_{2}-\mathbf{y}_{1}\right)^{2}}}
$$
```
Any help would be greatly appreciated
https://redd.it/12mrm5e
@r_bash
[SOLVED]
Edit:
#!/bin/bash
xfce4-screenshooter --region --save /home/$USER/"formula.jpg"
p2t predict -i ./formula.jpg > ./output 2>&1
sed -n '/Only texts:/,$p' /home/bob/output | grep -v 'Only te>
`This worked`
I wrote a noscript to execute a command and only get part of the output return out of it. But I failed, Now I need your help to make the noscript return output which is after the string "Only Texts:".
The Script I used it [ChatGPT helped with the selection part]
#!/bin/bash
xfce4-screenshooter --region --save /home/$USER/Pictures/Screenshots/"formula.jpg"
output=$(p2t predict -i ./formula.jpg)
out=$(echo "$output" | grep -oP 'Only texts:.*?\$\$')
echo "${out:12}"
The output I recieve if I echo `output` is
```
$ ./pic2text
[INFO 2023-04-15 11:09:48,368 select_device:104] YOLOv7 🚀 2023-4-14 torch 2.0.0+cu117 CPU
[INFO 2023-04-15 11:09:48,368 __init__:161] Use model: /home/bob/.cnstd/1.2/analysis/mfd-yolov7_tiny.pt
[INFO 2023-04-15 11:09:48,544 __init__:597]
[INFO 2023-04-15 11:09:48,682 _get_model:178] use model: /home/bob/.cnocr/2.2/densenet_lite_136-fc/cnocr-v2.2-densenet_lite_136-fc-epoch=039-complete_match_epoch=0.8597-model.onnx
[INFO 2023-04-15 11:09:48,713 _assert_and_prepare_model_files:135] use model: /home/bob/.cnstd/1.2/ppocr/ch_PP-OCRv3_det_infer.onnx
[INFO 2023-04-15 11:09:48,760 _assert_and_prepare_model_files:110] use model: /home/bob/.cnocr/2.2/ppocr/en_PP-OCRv3_rec_infer.onnx
[INFO 2023-04-15 11:09:48,825 _assert_and_prepare_model_files:135] use model: /home/bob/.cnstd/1.2/ppocr/en_PP-OCRv3_det_infer.onnx
[INFO 2023-04-15 11:09:48,866 download_checkpoints:50] use model weights.pth from path /home/bob/.pix2text/formular
[INFO 2023-04-15 11:09:48,866 download_checkpoints:50] use model image_resizer.pth from path /home/bob/.pix2text/formular
[WARNING 2023-04-15 11:09:49,419 _showwarnmsg:109] /home/bob/.local/lib/python3.9/site-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3483.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
[INFO 2023-04-15 11:09:49,422 _analyze_one:338] Done. (68.7ms) Inference, (0.6ms) NMS
[INFO 2023-04-15 11:09:50,266 predict:119] In image: ./formula.jpg
Outs:
[{'position': array([[ 8, 15],
[ 459, 15],
[ 459, 110],
[ 8, 110]]),
'text': '$$\n'
'\\operatorname{d}={\\sqrt{\\left(x_{2}-\\chi_{3}\\right)^{2}+\\left(y_{2}-\\mathbf{y}_{1}\\right)^{2}}}\n'
'$$',
'type': 'isolated'}]
Only texts:
$$
\operatorname{d}={\sqrt{\left(x_{2}-\chi_{3}\right)^{2}+\left(y_{2}-\mathbf{y}_{1}\right)^{2}}}
$$
output
```
All, I want is (stuff after Only texts:)
```
$$
\operatorname{d}={\sqrt{\left(x_{2}-\chi_{3}\right)^{2}+\left(y_{2}-\mathbf{y}_{1}\right)^{2}}}
$$
```
Any help would be greatly appreciated
https://redd.it/12mrm5e
@r_bash
Reddit
r/bash on Reddit: Need help filtering the output after phrase "Only Texts:"
Posted by u/Secure_Tomatillo_375 - No votes and 2 comments
Execute local sh on remote machine
Hi guys, is there any way I can execute a noscript that's in my local machine on remote ones?
I need to run a series of test on several systems every day so, I made a noscript for It. Right now I have that noscript on a pen that I insert into each of those system, mount, and run but, if I could do this from my local machine it would be so much more efficient.
Any tips?
Thanks in advance.
https://redd.it/12n08ii
@r_bash
Hi guys, is there any way I can execute a noscript that's in my local machine on remote ones?
I need to run a series of test on several systems every day so, I made a noscript for It. Right now I have that noscript on a pen that I insert into each of those system, mount, and run but, if I could do this from my local machine it would be so much more efficient.
Any tips?
Thanks in advance.
https://redd.it/12n08ii
@r_bash
Reddit
r/bash on Reddit: Execute local sh on remote machine
Posted by u/stringburner - No votes and 1 comment
Pull variables, with specific prefix, from env and create request
I have a bunch of noscripts like this one with a bunch of variables defined.
I'm looking for a way to not define all of those and perhaps pull them from the
Any suggestions on how to...
1. Pull all the variables?
2. Create the request body string?
https://redd.it/12n0jrl
@r_bash
I have a bunch of noscripts like this one with a bunch of variables defined.
I'm looking for a way to not define all of those and perhaps pull them from the
env if there's a variable prefixed with IM_.Any suggestions on how to...
1. Pull all the variables?
2. Create the request body string?
https://redd.it/12n0jrl
@r_bash
GitHub
im-manager/deploy-dhis2.sh at master · dhis2-sre/im-manager
Contribute to dhis2-sre/im-manager development by creating an account on GitHub.
how to make a noscript write to a permission dienied file?
I want to make a noscript to change the brightness of my screen, but i cant seem to get permision to write to that file. ive tryed all sorts of sudoing, even tee , but notthing works. help. Also is it possible to make this write to the file without asking for sudo password everytime i want to use it, without haveing to change the permissions for the brightness file itself. ther is a program called brightnessctl that basicly does this and i wanted to try to write my own version.
\#!/bin/bash
echo "How bright do you want me? (0-255) : "
read brightnessAmount
echo $brightnessAmount | sudo tee /sys/class/backlight/brightness
https://redd.it/12o4tr9
@r_bash
I want to make a noscript to change the brightness of my screen, but i cant seem to get permision to write to that file. ive tryed all sorts of sudoing, even tee , but notthing works. help. Also is it possible to make this write to the file without asking for sudo password everytime i want to use it, without haveing to change the permissions for the brightness file itself. ther is a program called brightnessctl that basicly does this and i wanted to try to write my own version.
\#!/bin/bash
echo "How bright do you want me? (0-255) : "
read brightnessAmount
echo $brightnessAmount | sudo tee /sys/class/backlight/brightness
https://redd.it/12o4tr9
@r_bash
Reddit
r/bash on Reddit: how to make a noscript write to a permission dienied file?
Posted by u/Wise_Opportunity_857 - No votes and no comments