Copy previous output in tmux
i have this really neat config for `foot` terminal which lets me copy previous output
file `~/.bashrc`:
command_done() {
printf '\e]133;D\e\\'
}
PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }command_done
file `~/.config/foot/`:
[key-bindings]
pipe-command-output=[sh -c "f=$(mktemp); cat - > $f; wl-copy < $f"] Control+Shift+g
for some reason this doesn't work in tmux
i know tmux can select with `tmux prefix` + `[`, `ctrl` + `space`, `enter`
but this requires to manually select with arrow keys.
https://redd.it/1du9wwu
@r_bash
i have this really neat config for `foot` terminal which lets me copy previous output
file `~/.bashrc`:
command_done() {
printf '\e]133;D\e\\'
}
PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }command_done
file `~/.config/foot/`:
[key-bindings]
pipe-command-output=[sh -c "f=$(mktemp); cat - > $f; wl-copy < $f"] Control+Shift+g
for some reason this doesn't work in tmux
i know tmux can select with `tmux prefix` + `[`, `ctrl` + `space`, `enter`
but this requires to manually select with arrow keys.
https://redd.it/1du9wwu
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Bug in bash? (CWD changing in weird ways)
I've found an interesting issue in bash:
[\~\] $ mkdir a a/b
[\~\] $ cd a/b
[\~\] $ rm -r ../../a
[\~\] $ env -i PS1='[\\w\] $ ' bash --norc
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[.\] $ cd ..
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[..\] $ cd .
[..\] $ ls
directory listing for \~, although I only did `cd ..` once.
From now on, every subsequent `cd .` or `cd ""` will apply a `cd ..` operation (instead of staying in the CWD). Similarly, a `cd ..` would go up two directories (instead of one), then three, then four, etc.
What could be some reason for this?
https://redd.it/1duhm4f
@r_bash
I've found an interesting issue in bash:
[\~\] $ mkdir a a/b
[\~\] $ cd a/b
[\~\] $ rm -r ../../a
[\~\] $ env -i PS1='[\\w\] $ ' bash --norc
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[.\] $ cd ..
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[..\] $ cd .
[..\] $ ls
directory listing for \~, although I only did `cd ..` once.
From now on, every subsequent `cd .` or `cd ""` will apply a `cd ..` operation (instead of staying in the CWD). Similarly, a `cd ..` would go up two directories (instead of one), then three, then four, etc.
What could be some reason for this?
https://redd.it/1duhm4f
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Is this bash noscript safe ?
This was posted online and meant to be downloaded from a web server and ran like this:
curl -fsSL https://example.com/url | bash -s --
or this
curl -fsSL https://example.com/url | bash -s -- 1.1.1.1
The purpose of the noscript is to verify that your system resolver or the resolver added as a positional parameter will be accepted by spamhaus for spam verification.
I will never run a curl http://example.com/url | bash noscript. but i did download this one and checked it out.
Is it safe ? Can somehow additonal positional paramaters be added to the downloaded noscript ?
my concerns
1. It is way to convoluted
2. the positional parameter later has an @ sign prepended. This is to define the nameserver to query with dig but what does on later bothers me . line 33
3. line 47 is the main line . somehow can the positional paramaters which are now in $dns be manipulated to do other things. Then the whole reversal with awk. then it echos a variable ?
I added line numbers to the noscript. thanks
https://redd.it/1duq3ic
@r_bash
This was posted online and meant to be downloaded from a web server and ran like this:
curl -fsSL https://example.com/url | bash -s --
or this
curl -fsSL https://example.com/url | bash -s -- 1.1.1.1
The purpose of the noscript is to verify that your system resolver or the resolver added as a positional parameter will be accepted by spamhaus for spam verification.
I will never run a curl http://example.com/url | bash noscript. but i did download this one and checked it out.
Is it safe ? Can somehow additonal positional paramaters be added to the downloaded noscript ?
my concerns
1. It is way to convoluted
2. the positional parameter later has an @ sign prepended. This is to define the nameserver to query with dig but what does on later bothers me . line 33
3. line 47 is the main line . somehow can the positional paramaters which are now in $dns be manipulated to do other things. Then the whole reversal with awk. then it echos a variable ?
I added line numbers to the noscript. thanks
1> #!/usr/bin/env bash2> dnsip="$1"3> test_IP='127.0.0.4'4> if [[ -t 1 ]]; then5> AZ="$(tput setaf 45)"6> RO="$(tput setaf 160)"7> VE="$(tput setaf 40)"8> NO="$(tput sgr0)"9> else10> AZ=""11> RO=""12> VE=""13> NO=""14> fi15>16> # Function to validate ipv417> validate_ipv4() {18> if [[ -z "$1" ]]; then19> return 120> fi21> if grep -Pq '^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$' <<<"$1"; then22> return 023> else24> return 125> fi26> }27> # Check whether user has used an ip as dns server to test or use the default system name server28> if [[ -n "$dnsip" ]]; then29> if ! validate_ipv4 "$dnsip"; then30> echo "${RO}Error${NO}: $dnsip is not a valid ip v4"31> exit 132> fi33> dns="@$dnsip"34> else35> dns=''36> current_dns="$(grep '^nameserver' /etc/resolv.conf | head -1 | awk '{print $2}')"37> if ! validate_ipv4 "$current_dns"; then38> echo "${RO}Error${NO}: $current_dns is not a valid ip v4"39> exit 140> fi41> fi42>43> # Loop to test 10 times whether dns server is blocked/ignored by Spamhaus44> errors=045> for i in {01..10}; do46> # shellcheck disable=SC208647> out="$(dig +short txt $dns "$(echo "$test_IP" | awk -F '.' '{OFS="."; print $4,$3,$2,$1}' 2>/dev/null | sed 's/$/\.zen\.spamhaus\.org/')" | tr -d '"')"48> if grep -q 'Listed' <<<"$out" &>/dev/null; then49> echo "${VE}Test $i${NO}: $out"50> elif grep -q 'open resolver' <<<"$out" &>/dev/null; then51> echo "${RO}Test $i${NO}: $out"52> ((errors += 1))53> else54> echo "${RO}Test $i${NO}: Request ignored by Spamhaus or DNS Resolver timed out"55> ((errors += 1))56> fi57> sleep .158> done59>60> # Show result61> echo62> if [[ $errors -gt 0 ]]; then63> if [[ -n $dnsip ]]; then64> echo "Result is ${RO}bad${NO}, Spamhaus is blocking/ignoring the DNS Resolver ${AZ}$dnsip${NO}"65> exit 10066> else67> echo "Result is ${RO}bad${NO}, Spamhaus is blocking/ignoring your current DNS Resolver ${AZ}$current_dns{$NO}"68> exit 10069> fi70> else71> if [[ -n $dnsip ]]; then72> echo "Result is ${VE}good${NO}, Spamhaus works fine with the DNS Resolver ${AZ}$dnsip${NO}"73> else74> echo "Result is ${VE}good${NO}, Spamhaus works fine with your current DNS Resolver ${AZ}$current_dns${NO}"75> fi76>77> fihttps://redd.it/1duq3ic
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Why can't we inline command exit codes when using 'return'?
Why can't we inline command usage with the return keyword to simplify function exit codes?
Something like this:
function myrandomcommand() {
return anotherrandomfunction
}
Not to get this confused with getting the command output of the function, just the exit code from it.
I ask because there have been some occasions where all I want is the exit code from a command and have to call the command and then reference
Maybe like a command substitution but dedicated to retrieving the exit code like this:
function myrandomcommand() {
return @(anotherrandomfunction)
}
Has something like this already been implemented into bash and I'm just unaware of it, or is there a specific reason that this was left out? This might be too specific of an operator to be useful for everyone, so I'd understand if it was in fact left out.
https://redd.it/1duunm1
@r_bash
Why can't we inline command usage with the return keyword to simplify function exit codes?
Something like this:
function myrandomcommand() {
return anotherrandomfunction
}
Not to get this confused with getting the command output of the function, just the exit code from it.
I ask because there have been some occasions where all I want is the exit code from a command and have to call the command and then reference
$? (It's not like that's bad, but it would be cool to have something else to get the code).Maybe like a command substitution but dedicated to retrieving the exit code like this:
function myrandomcommand() {
return @(anotherrandomfunction)
}
Has something like this already been implemented into bash and I'm just unaware of it, or is there a specific reason that this was left out? This might be too specific of an operator to be useful for everyone, so I'd understand if it was in fact left out.
https://redd.it/1duunm1
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How can I automate these tree commands I frequently need to type out?
I would like to run:
git add .
git commit -m "Initial "commit"
git push
I got bored of typing them out each time. Can I make an alias or something like "gc" (for git commit). The commit message is always the same "Initial commit".
https://redd.it/1duw6ac
@r_bash
I would like to run:
git add .
git commit -m "Initial "commit"
git push
I got bored of typing them out each time. Can I make an alias or something like "gc" (for git commit). The commit message is always the same "Initial commit".
https://redd.it/1duw6ac
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Is there a way I can ctrl-z a noscript without it stopping after resume?
I'm having to do processing of data using a noscript that will take a couple weeks. I would like to be able to pause the operations temporarly so that I can run other stuff as needed and then resume, but when I do this, it will finish whatever process the noscript happened to be on and then just quit.
I would like to be able to pause and resume a noscript without it doing this. Any help would be appreciated.
https://redd.it/1duxbbg
@r_bash
I'm having to do processing of data using a noscript that will take a couple weeks. I would like to be able to pause the operations temporarly so that I can run other stuff as needed and then resume, but when I do this, it will finish whatever process the noscript happened to be on and then just quit.
I would like to be able to pause and resume a noscript without it doing this. Any help would be appreciated.
https://redd.it/1duxbbg
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Bash custom completion not working correctly
I have this noscript
#!/bin/bash
fuzzycomplete() {
# Check if initcompletion is available
if declare -F initcompletion >/dev/null 2>&1; then
initcompletion || return
else
# Manual initialization for older bash versions
COMPREPLY=()
cur="${COMPWORDS[COMPCWORD]}"
prev="${COMPWORDS[COMPCWORD-1]}"
words=("${COMPWORDS[@]}")
cword="${COMPCWORD}"
fi
local IFS=$'\n'
local suggestions=($(compgen -f -- "${cur}" | /home/vrin/rustfuzzer/target/debug/rustfuzzer "${cur}"))
if "${#suggestions[@}" -eq "1" ]; then
COMPREPLY=("${suggestions0}")
else
COMPREPLY=("${cur}")
fi
}
complete -F fuzzycomplete ls cd
and it's supposed to generate best-match completions through another rust program. When i interface with the program manually, using this command
it does output the best possible match. like it's not perfect but still, something is being printed. but when I try the same using this noscript, ie, source the noscript and then do ls <some text> and hit tab, it just takes me 4 spaces further. Won't give an output unless it matches exactly (like if i put Car it'll give me Cargo.lock, but nothing for car). can anyone help me in figuring out where this is going wrong
https://redd.it/1duw54i
@r_bash
I have this noscript
#!/bin/bash
fuzzycomplete() {
# Check if initcompletion is available
if declare -F initcompletion >/dev/null 2>&1; then
initcompletion || return
else
# Manual initialization for older bash versions
COMPREPLY=()
cur="${COMPWORDS[COMPCWORD]}"
prev="${COMPWORDS[COMPCWORD-1]}"
words=("${COMPWORDS[@]}")
cword="${COMPCWORD}"
fi
local IFS=$'\n'
local suggestions=($(compgen -f -- "${cur}" | /home/vrin/rustfuzzer/target/debug/rustfuzzer "${cur}"))
if "${#suggestions[@}" -eq "1" ]; then
COMPREPLY=("${suggestions0}")
else
COMPREPLY=("${cur}")
fi
}
complete -F fuzzycomplete ls cd
and it's supposed to generate best-match completions through another rust program. When i interface with the program manually, using this command
ls | /****/****/rust_fuzzer/target/debug/rust_fuzzer hashit does output the best possible match. like it's not perfect but still, something is being printed. but when I try the same using this noscript, ie, source the noscript and then do ls <some text> and hit tab, it just takes me 4 spaces further. Won't give an output unless it matches exactly (like if i put Car it'll give me Cargo.lock, but nothing for car). can anyone help me in figuring out where this is going wrong
https://redd.it/1duw54i
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Portable alternative to fmt/fold with multibyte chars support?
Recently, I've found out multibyte chars support in fmt/fold is a BSD thing. Sample text in Greek:
Αυτό είναι ένα παράδειγμα κειμένου στα ελληνικά. Αυτό το κείμενο χρησιμοποιείται για την επίδειξη της μορφοποίησης των γραμμών.
FreeBSD, OpenBSD, NetBSD:
> LCALL=enUS.UTF-8 fold -s -w60 < gr
Αυτό είναι ένα παράδειγμα κειμένου στα ελληνικά. Αυτό το
κείμενο χρησιμοποιείται για την επίδειξη της μορφοποίησης
των γραμμών.
> LCALL=enUS.UTF-8 fmt < gr
Αυτό είναι ένα παράδειγμα κειμένου στα ελληνικά. Αυτό το κείμενο
χρησιμοποιείται για την επίδειξη της μορφοποίησης των γραμμών.
Ubuntu:
> LCALL=enUS.UTF-8 fold -s -w60 < gr
Αυτό είναι ένα παράδειγμα
κειμένου στα ελληνικά. Αυτό το
κείμενο χρησιμοποιείται για την
επίδειξη της μορφοποίησης των
γραμμών.
> LCALL=enUS.UTF-8 fmt < gr
Αυτό είναι ένα παράδειγμα κειμένου
στα ελληνικά. Αυτό το κείμενο
χρησιμοποιείται για την επίδειξη της
μορφοποίησης των γραμμών.
Evidently, GNU fold/fmt in Ubuntu do count bytes, not chars.
Is there some portable alternative, which is not a custom awk, perl etc noscript?
https://redd.it/1dv67wl
@r_bash
Recently, I've found out multibyte chars support in fmt/fold is a BSD thing. Sample text in Greek:
Αυτό είναι ένα παράδειγμα κειμένου στα ελληνικά. Αυτό το κείμενο χρησιμοποιείται για την επίδειξη της μορφοποίησης των γραμμών.
FreeBSD, OpenBSD, NetBSD:
> LCALL=enUS.UTF-8 fold -s -w60 < gr
Αυτό είναι ένα παράδειγμα κειμένου στα ελληνικά. Αυτό το
κείμενο χρησιμοποιείται για την επίδειξη της μορφοποίησης
των γραμμών.
> LCALL=enUS.UTF-8 fmt < gr
Αυτό είναι ένα παράδειγμα κειμένου στα ελληνικά. Αυτό το κείμενο
χρησιμοποιείται για την επίδειξη της μορφοποίησης των γραμμών.
Ubuntu:
> LCALL=enUS.UTF-8 fold -s -w60 < gr
Αυτό είναι ένα παράδειγμα
κειμένου στα ελληνικά. Αυτό το
κείμενο χρησιμοποιείται για την
επίδειξη της μορφοποίησης των
γραμμών.
> LCALL=enUS.UTF-8 fmt < gr
Αυτό είναι ένα παράδειγμα κειμένου
στα ελληνικά. Αυτό το κείμενο
χρησιμοποιείται για την επίδειξη της
μορφοποίησης των γραμμών.
Evidently, GNU fold/fmt in Ubuntu do count bytes, not chars.
Is there some portable alternative, which is not a custom awk, perl etc noscript?
https://redd.it/1dv67wl
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
What is the best and faster tool for counting lines in a file that matches a specific pattern. The text file is quite a large one about 4GB
https://redd.it/1dva3ph
@r_bash
https://redd.it/1dva3ph
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Add command into an existing variable (curl+torsocks usage)
I have an existing variable
PREVIEW=$(curl -Ls $URL)
if the output of the variable
what is the correct way to launch
Thanks in advance.
https://redd.it/1dvffrr
@r_bash
I have an existing variable
PREVIEW=$(curl -Ls $URL)
if the output of the variable
$PREVIEW results empty (maybe because api limit is reached), I want to add torsocks before curl and then retrywhat is the correct way to launch
torsocks curl -Ls $URL? I've tried to eval $PREVIEW without success.Thanks in advance.
https://redd.it/1dvffrr
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Help with color formatting / redirection in bash wrapper function?
**TD;LR - This one is probably more involved. I have a `wrapper` function ([pastebin](https://pastebin.com/skxQJpQ2)) that works perfectly for capturing `stdout` but seems to blow up when I attempt the same tricks with `stderr`. I'm assuming I'm doing *something* wrong but have no idea what.**
A little over a week ago, I had asked a question about [redirection](https://old.reddit.com/r/bash/comments/1dnxehx/question_about_stream_redirection_file_denoscriptors/) and got some excellent answers from you guys that really helped. Since then, I've been trying to adapt what I learned there to create a more flexible wrapper function capable of the following:
- wrapping a call to some passed application + its args (e.g. `curl`, `traceroute`, some other bash function, etc)
- capturing stderr, stdout, and return code of the passed call to local variables (with the intention of being able to export these to named variables that are passed to the wrapper function - I have done this in other functions and am not worried about this part, so that's out of scope in the examples below): Solved
- allow selectively printing stderr / stdout in real time so that certain commands like `traceroute reddit.com` (progress on stdout) / `curl --no-clobber -L -A "${userAgent}" "${url}" -O "${fileName}"` (progress on stderr) / etc can still be displayed while the command is still running: Solved - mostly based on adapting [this](https://stackoverflow.com/questions/12451278/capture-stdout-to-a-variable-but-still-display-it-in-the-console)
- Preserve colors in captured variables: Solved
- Preserve colors in realtime output: partially solved (works for stdout but not for stderr)
Using u/Ulfnic 's excellent [suggestion](https://old.reddit.com/r/bash/comments/1dnxehx/question_about_stream_redirection_file_denoscriptors/la6gcuu/) as a base, I've almost got everything I want but I'm stumped by the color output I'm getting. I've been over this a dozen times and I'm not seeing anything that sticks out... but obviously it is not behaving as desired.
I'm (currently) on Fedora 39 which has
$ bash --version | head -1
GNU bash, version 5.2.26(1)-release (x86_64-redhat-linux-gnu)
The functions I am using are defined [here](https://pastebin.com/skxQJpQ2) which I have saved as `funcs.sh` and am loading using `. funcs.sh`.
The expected usages:
A) running the wrapper function with no options and passing it a command (plus args) to be executed, it will capture stderr, stdout, and return code to separate internal variables which can be acted on later. This works perfectly and its output looks like this
https://files.catbox.moe/rk02vz.png
B) running the wrapper function with the `-O` option will print stdout in realtime so commands like `traceroute` can give progress updates without waiting for the app to finish running before output is displayed. Should still do all the same things as (A) but additionally print stdout in realtime, while preserving color. This also works perfectly and its output looks like this
https://files.catbox.moe/8a7iq0.png
C) running the wrapper function with the `-E` option will print stderr in realtime so commands like `curl` can give progress updates without waiting for the app to finish running before output is displayed. Should still do all the same things as (A) but additionally print stderr in realtime, while preserving color.
This one is broken but I don't even understand why the code isn't working as expected. Its output looks like this
https://files.catbox.moe/obryvu.png
Functionally, it has a few issues:
1. It is incorrectly capturing stderr output to the local variable `outstr`.
2. The realtime printing of stderr loses all color for some reason, even though AFAICT the handling for stdout and stderr is identical
3. The local variable `errstr` loses all color formatting, despite the incorrectly assigned `outstr` preserving it.
When I run `wrapper -E realTimeStderrTest` (e.g. the un-colorized version of the same test), it works perfectly (issue \#1 does
**TD;LR - This one is probably more involved. I have a `wrapper` function ([pastebin](https://pastebin.com/skxQJpQ2)) that works perfectly for capturing `stdout` but seems to blow up when I attempt the same tricks with `stderr`. I'm assuming I'm doing *something* wrong but have no idea what.**
A little over a week ago, I had asked a question about [redirection](https://old.reddit.com/r/bash/comments/1dnxehx/question_about_stream_redirection_file_denoscriptors/) and got some excellent answers from you guys that really helped. Since then, I've been trying to adapt what I learned there to create a more flexible wrapper function capable of the following:
- wrapping a call to some passed application + its args (e.g. `curl`, `traceroute`, some other bash function, etc)
- capturing stderr, stdout, and return code of the passed call to local variables (with the intention of being able to export these to named variables that are passed to the wrapper function - I have done this in other functions and am not worried about this part, so that's out of scope in the examples below): Solved
- allow selectively printing stderr / stdout in real time so that certain commands like `traceroute reddit.com` (progress on stdout) / `curl --no-clobber -L -A "${userAgent}" "${url}" -O "${fileName}"` (progress on stderr) / etc can still be displayed while the command is still running: Solved - mostly based on adapting [this](https://stackoverflow.com/questions/12451278/capture-stdout-to-a-variable-but-still-display-it-in-the-console)
- Preserve colors in captured variables: Solved
- Preserve colors in realtime output: partially solved (works for stdout but not for stderr)
Using u/Ulfnic 's excellent [suggestion](https://old.reddit.com/r/bash/comments/1dnxehx/question_about_stream_redirection_file_denoscriptors/la6gcuu/) as a base, I've almost got everything I want but I'm stumped by the color output I'm getting. I've been over this a dozen times and I'm not seeing anything that sticks out... but obviously it is not behaving as desired.
I'm (currently) on Fedora 39 which has
$ bash --version | head -1
GNU bash, version 5.2.26(1)-release (x86_64-redhat-linux-gnu)
The functions I am using are defined [here](https://pastebin.com/skxQJpQ2) which I have saved as `funcs.sh` and am loading using `. funcs.sh`.
The expected usages:
A) running the wrapper function with no options and passing it a command (plus args) to be executed, it will capture stderr, stdout, and return code to separate internal variables which can be acted on later. This works perfectly and its output looks like this
https://files.catbox.moe/rk02vz.png
B) running the wrapper function with the `-O` option will print stdout in realtime so commands like `traceroute` can give progress updates without waiting for the app to finish running before output is displayed. Should still do all the same things as (A) but additionally print stdout in realtime, while preserving color. This also works perfectly and its output looks like this
https://files.catbox.moe/8a7iq0.png
C) running the wrapper function with the `-E` option will print stderr in realtime so commands like `curl` can give progress updates without waiting for the app to finish running before output is displayed. Should still do all the same things as (A) but additionally print stderr in realtime, while preserving color.
This one is broken but I don't even understand why the code isn't working as expected. Its output looks like this
https://files.catbox.moe/obryvu.png
Functionally, it has a few issues:
1. It is incorrectly capturing stderr output to the local variable `outstr`.
2. The realtime printing of stderr loses all color for some reason, even though AFAICT the handling for stdout and stderr is identical
3. The local variable `errstr` loses all color formatting, despite the incorrectly assigned `outstr` preserving it.
When I run `wrapper -E realTimeStderrTest` (e.g. the un-colorized version of the same test), it works perfectly (issue \#1 does
Pastebin
WIP wrapper function for capturing stderr/stdout/rc to vars + optionally printing stdout/stderr - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
not happen but issues \#2 and \#3 aren't applicable in black and white mode) so I am assuming it is something related to colors that it doesn't like but I have no clue what exactly. That output is [here](https://files.catbox.moe/zqnae9.png)
https://redd.it/1dvmij1
@r_bash
https://redd.it/1dvmij1
@r_bash
why are mode bits represented in bash in both octally? AND symbolically? or alphabetically?
so i understand that file permissions in mode bits are represented alphabetically, or symbolically?
r = read
w = write
x = execute
now if i want to change this with chmod, i need to do this with octals?
x = 1
w = w
r = 4
can someone explain this to me? why are there two systems?
https://redd.it/1dw0hgq
@r_bash
so i understand that file permissions in mode bits are represented alphabetically, or symbolically?
r = read
w = write
x = execute
now if i want to change this with chmod, i need to do this with octals?
x = 1
w = w
r = 4
can someone explain this to me? why are there two systems?
https://redd.it/1dw0hgq
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Displaying stdout from continuously running program and run command if string present
Hi, I have a noscript that runs in a terminal window, and I need to see the displayed stdout from a program that it launches, which continues running. But I also need to monitor the program's stdout and run a command if a string eventually appears in the output. Once that condition is met then I don't want to see the terminal anymore so I kill the terminal, but the program keeps running until I exit its window. I would prefer to not have to write the stdout to a file for parsing. This is as close as I can get, but it doesn't show the program's output. Any tips? Thanks!
#!/bin/bash
thisPID="$(echo $$)"
docker container start Something
nohup xfreerdp /v:localhost |
grep --line-buffered 'PDUTYPEDATA' |
while read; do
wmctrl -c 'FreeRDP' -b toggle,maximizedvert,maximizedhorz;
kill $thisPID
done
https://redd.it/1dw291c
@r_bash
Hi, I have a noscript that runs in a terminal window, and I need to see the displayed stdout from a program that it launches, which continues running. But I also need to monitor the program's stdout and run a command if a string eventually appears in the output. Once that condition is met then I don't want to see the terminal anymore so I kill the terminal, but the program keeps running until I exit its window. I would prefer to not have to write the stdout to a file for parsing. This is as close as I can get, but it doesn't show the program's output. Any tips? Thanks!
#!/bin/bash
thisPID="$(echo $$)"
docker container start Something
nohup xfreerdp /v:localhost |
grep --line-buffered 'PDUTYPEDATA' |
while read; do
wmctrl -c 'FreeRDP' -b toggle,maximizedvert,maximizedhorz;
kill $thisPID
done
https://redd.it/1dw291c
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Text pasted to a file not parsed correctly (invisible characters)
I have a noscript which parses text on a line-by-line basis. Works as expected, except for text pasted from a particular webpage that involves both English text and foreign characters (cannot share more details than that), where it seems to parse every *other* line by the shell. However, if I `echo` *instead* of running `yt-dlp` on what's parsed, it still prints expected values of `$noscript` and `$url`. I was told there are invisible characters involved like `$'\r'` byte (0x0d) which bash does not consider as whitespaces to ignore, but how can I see if this is the case on a text editor (I use Neovim) and/or fix the cause of the issue? If I append a character manually to each line that was pasted, the noscript then parses each line as you would expect and is a workaround for the issue.
file="$2"
while IFS= read -r line || [[ -n "$line" ]]; do
noscript="${line#* }"
url="${line%% *}"
if [[ -n "$noscript" ]]; then
default_template="$noscript - %(uploader).12B (%(upload_date)s) %(id)s.%(ext)s"
else
default_template="%(noscript).140B - %(uploader).12B (%(upload_date)s) %(id)s.%(ext)s"
fi
yt-dlp --output "$default_template" "$url"
# echo "$url"
done < <( awk NF "$file" ) # Delete blank lines from $file
exit
https://redd.it/1dw8l6e
@r_bash
I have a noscript which parses text on a line-by-line basis. Works as expected, except for text pasted from a particular webpage that involves both English text and foreign characters (cannot share more details than that), where it seems to parse every *other* line by the shell. However, if I `echo` *instead* of running `yt-dlp` on what's parsed, it still prints expected values of `$noscript` and `$url`. I was told there are invisible characters involved like `$'\r'` byte (0x0d) which bash does not consider as whitespaces to ignore, but how can I see if this is the case on a text editor (I use Neovim) and/or fix the cause of the issue? If I append a character manually to each line that was pasted, the noscript then parses each line as you would expect and is a workaround for the issue.
file="$2"
while IFS= read -r line || [[ -n "$line" ]]; do
noscript="${line#* }"
url="${line%% *}"
if [[ -n "$noscript" ]]; then
default_template="$noscript - %(uploader).12B (%(upload_date)s) %(id)s.%(ext)s"
else
default_template="%(noscript).140B - %(uploader).12B (%(upload_date)s) %(id)s.%(ext)s"
fi
yt-dlp --output "$default_template" "$url"
# echo "$url"
done < <( awk NF "$file" ) # Delete blank lines from $file
exit
https://redd.it/1dw8l6e
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Is there any sense in quoting special vars like $? and $# ?
I mean, bash and other shells are aware
https://redd.it/1dwq3no
@r_bash
I mean, bash and other shells are aware
$? and $# cant contain any spaces or patterns, so I guess they treat $? and "$?" the same? Or do they still try to perform word splitting on $? ?https://redd.it/1dwq3no
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Trying to send multiple flags to rsync
So I use rsync over ssh to move files over my local network. I'm not worried about security too much, but use rsync over ssh so I can do it over internet sporadically.
This is what works:
export DEN=username@den.local
export USER=/home/kitchen
rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' -rptuv --delete --progress $DEN:/home/username/Music/English/A/ $USER/Music/Music/A/
I am trying to put all the flags in a variable.
The following variable doesn't work
export RSYNCFLAGS="-e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' -rptuv --delete --progress"
rsync $RSYNCFLAGS $DEN:/home/username/Music/English/A/ $USER/Music/Music/A
I also tried using a variable array, but that didn't work as expected:
export RSYNCFLAGS=(-e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' -rptuv --delete --progress)
rsync ${RSYNCFLAGS*} $DEN:/home/username/Music/English/A/ $USER/Music/Music/A
They both have problems with the -e at the beginning (it doesn't add it to the variable at all). When I move that later on, it still gives a problem. Can anyone help me out?
https://redd.it/1dwquoi
@r_bash
So I use rsync over ssh to move files over my local network. I'm not worried about security too much, but use rsync over ssh so I can do it over internet sporadically.
This is what works:
export DEN=username@den.local
export USER=/home/kitchen
rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' -rptuv --delete --progress $DEN:/home/username/Music/English/A/ $USER/Music/Music/A/
I am trying to put all the flags in a variable.
The following variable doesn't work
export RSYNCFLAGS="-e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' -rptuv --delete --progress"
rsync $RSYNCFLAGS $DEN:/home/username/Music/English/A/ $USER/Music/Music/A
I also tried using a variable array, but that didn't work as expected:
export RSYNCFLAGS=(-e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' -rptuv --delete --progress)
rsync ${RSYNCFLAGS*} $DEN:/home/username/Music/English/A/ $USER/Music/Music/A
They both have problems with the -e at the beginning (it doesn't add it to the variable at all). When I move that later on, it still gives a problem. Can anyone help me out?
https://redd.it/1dwquoi
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Experience customizing the colors on "ohmybash"?
I was wondering if anyone here has the experience of altering or modifying the provided themes in "Ohmybash" I'm trying to change the powerline and text color on my "agnoster" theme but no luck thus far.
https://redd.it/1dwyh4m
@r_bash
I was wondering if anyone here has the experience of altering or modifying the provided themes in "Ohmybash" I'm trying to change the powerline and text color on my "agnoster" theme but no luck thus far.
https://redd.it/1dwyh4m
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Parameter Substitution and Pattern Matching in bash
Hi. I may have misread the documentation, but why doesn't this work?
Suppose var="ciaomamma0comestai"
I'd like to print until the 0 (included)
I tried echo ${var%%[:alpha:\]} but it doesn't work
According to the Parameter Expansion doc
>
The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching).
But Patter Matching doc clearly says
>Within ‘[’ and ‘\]’, character classes can be specified using the syntax [:class:\], where class is one of the following classes defined in the POSIX standard:
alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit
So that above command should work...
I know there are other solutions, like {var%%0*} but it's not as elegant and does not cover cases where there could be other numbers instead of 0
https://redd.it/1dxix8c
@r_bash
Hi. I may have misread the documentation, but why doesn't this work?
Suppose var="ciaomamma0comestai"
I'd like to print until the 0 (included)
I tried echo ${var%%[:alpha:\]} but it doesn't work
According to the Parameter Expansion doc
>
${parameter%%word} The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching).
But Patter Matching doc clearly says
>Within ‘[’ and ‘\]’, character classes can be specified using the syntax [:class:\], where class is one of the following classes defined in the POSIX standard:
alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit
So that above command should work...
I know there are other solutions, like {var%%0*} but it's not as elegant and does not cover cases where there could be other numbers instead of 0
https://redd.it/1dxix8c
@r_bash
www.gnu.org
Shell Parameter Expansion (Bash Reference Manual)
Next: Command Substitution, Previous: Tilde Expansion, Up: Shell Expansions [Contents][Index]
a serialized dictionary argument parser for Bash (pip-installable)
Hey all, I built a serialized dictionary argument parser for Bash, that is pip-installable,
pip install blue_options
then add this line to your `~/.bash_profile` or `~/.bashrc`,
source $(python -m blue_options locate)/.bash/blue_options.sh
it can parse a serialized dictionary as an argument; for example,
area=<vancouver>,~batch,count=<-1>,dryrun,gif,model=<model-id>,~process,publish,~upload
like this,
function func() {
local options=$1
local var=$(abcli_options "$options" var default)
local key=$(abcli_options_int "$options" key 0)
[[ "$key" == 1 ]] &&
echo "var=$var"
}
more: [https://github.com/kamangir/blue-options](https://github.com/kamangir/blue-options) + [https://pypi.org/project/blue-options/](https://pypi.org/project/blue-options/)
https://redd.it/1dxmewr
@r_bash
Hey all, I built a serialized dictionary argument parser for Bash, that is pip-installable,
pip install blue_options
then add this line to your `~/.bash_profile` or `~/.bashrc`,
source $(python -m blue_options locate)/.bash/blue_options.sh
it can parse a serialized dictionary as an argument; for example,
area=<vancouver>,~batch,count=<-1>,dryrun,gif,model=<model-id>,~process,publish,~upload
like this,
function func() {
local options=$1
local var=$(abcli_options "$options" var default)
local key=$(abcli_options_int "$options" key 0)
[[ "$key" == 1 ]] &&
echo "var=$var"
}
more: [https://github.com/kamangir/blue-options](https://github.com/kamangir/blue-options) + [https://pypi.org/project/blue-options/](https://pypi.org/project/blue-options/)
https://redd.it/1dxmewr
@r_bash
GitHub
GitHub - kamangir/blue-options: 🌀 an options for Bash.
🌀 an options for Bash. Contribute to kamangir/blue-options development by creating an account on GitHub.
Help customizing "OhMyBash"?
How can I get the color #55c369 as the color for my prompts background on the agnoster theme , It seems like "OhMyBash" uses the 'ANSI' color code--So how would I get the color translated to ANSI if that possible? Currently my prompt is displaying the opposite color way I want
What I currently have\^
What I would like to have\^
https://redd.it/1dxnvzg
@r_bash
How can I get the color #55c369 as the color for my prompts background on the agnoster theme , It seems like "OhMyBash" uses the 'ANSI' color code--So how would I get the color translated to ANSI if that possible? Currently my prompt is displaying the opposite color way I want
What I currently have\^
What I would like to have\^
https://redd.it/1dxnvzg
@r_bash