r_bash – Telegram
stdin read question

ls -1 | while IFS= read -r line; do
echo "$line"
read -p "Press Enter to continue..."
done

Why does this not prompt after every ls line?

It should pause after every line, cause thats how stdin & read works?

And what would be a workaround to make this work as i exect?

https://redd.it/1dxlqb1
@r_bash
How do I handle window decoration offsets when positing windows with xdotool or wmctrl?

Here's two examples of positing windows to X=40 Y=40 and changing their size to 1000x600:

wmctrl -r :ACTIVE: -e '0,40,40,1000,600'

xdotool getactivewindow windowmove %@ 20 20 windowsize %@ 1000 600

Depending on the program both wmctrl and xdotool will calculate that 40 X/Y position BEFORE or AFTER window decorations. So some programs will always be placed at X Y where others will always be placed at X+DEC_WIDTH_LEFT Y+DEC_HEIGHT_TOP.

I don't mind adding my own decoration offsets but I have no way of telling programmatically which windows should have that offest applied.

So far i've tried the following but neither gives me a property that distinguishes between them:


xdotool getactivewindow getwindowname getwindowgeometry --shell

xprop -id "$(xdotool getactivewindow)"

xwininfo -id "$(xdotool getactivewindow)"

Here's a list of programs based on how they're positioned realtive to decorations:

# Placement BEFORE decorations
krita
mpv
libreoffice {writer,calc,math,ect}
brave-browser

# Placement AFTER decorations
gimp
xarchiver
smplayer
alacritty
xfce4-terminal
thunar
chromium
firefox (with Title Bar enabled)

Glad for any insight, thank you.

https://redd.it/1dy6c7v
@r_bash
noscript no work halp

while sleep 0.5; do find . -name '.c' -o -name '.h' | entr -d make; done &
sh -c 'while sleep 0.5; do find . -name '.c' -o -name '.h' | entr -d make; done' &

Why does this not keep running in a background?
Its a closed while loop, but it seems to exit in a first iteration of the loop.

but without the & it works as expected

also entr, its just a simplified version of inotify

http://eradman.com/entrproject/

https://redd.it/1dy6jvr
@r_bash
.bash_history format

In bash, running the `history` command prints in a beautifully formatted output:

5625 [2024-06-22 12:22:38] F libdisplay-info
5626 [2024-06-22 12:22:50] p -Ssq libdisplay-info
5627 [2024-06-22 12:23:02] p -Fl libdisplay-info
5628 [2024-06-22 20:35:24] p -Flq libdisplay-info
5629 [2024-06-22 20:36:02] Q libdisplay-info

However, the .bash_history file looks like crap in comparison:

#1719084158
F libdisplay-info
#1719084170
p -Ssq libdisplay-info
#1719084182
p -Fl libdisplay-info
#1719113724
p -Flq libdisplay-info
#1719113762
Q libdisplay-info

I've hacked together an ugly, fragile bit of code to write a duplicate the first example to `"${HOME}"/.bash_history_dated`.

sed 'N;s/\n/ /' < "${HOME}"/.bash_history \
| cut -c2- \
| awk '{$1 = strftime("%F %r", substr($1,1,10))} 1 {print "["$1"] ",$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20}' \
> "${HOME}"/.bash_history_dated

This runs whenever I exit the shell via `trap "/home/jeff/bin/bash-history-timestamp" 0`, and the results (if there's not more than two lines input per command).
This is great, and I didn't want the command numbers included in this.

[2024-06-22 12:22:38 PM] F libdisplay-info
[2024-06-22 12:22:50 PM] p -Ssq libdisplay-info
[2024-06-22 12:23:02 PM] p -Fl libdisplay-info
[2024-06-22 08:35:24 PM] p -Flq libdisplay-info
[2024-06-22 08:36:02 PM] Q libdisplay-info

My questions are:

1) Why doesn't this work in place of the ugly code `history | cut -c 8- > "${HOME}"/.BASH_HIST_DATED`. This works in the shell, but only creates an empty file when ran in the noscript.

2) How to improve my ugly code to be cleaner and more robust to work with multiple cli input lines if it's the only solution.

https://redd.it/1dyl2ln
@r_bash
Running a remote command using EOF but only getting a fraction of the output before the noscript completes. How do I keep stdout open until the command completes? Is there a way to inject a "wait" command into EOF?

I'm running a command on a remote system. The remote system is not linux and I can't send piped/chained commands, so I have to use EOF (unless there's another alternative I'm not aware of.

The below command outputs \~12k lines when I run it on the console directly, but when I run it from my unix host, it gets a couple hundred before it logs out.

{
ssh user@host << EOF
\environment no more
\show mobile-gateway bearer-context | match 9/10
\logout
EOF
} > $output


I see the logout command being executed, so the remote system completed the show command, but the output isn't being captured on my side.

https://redd.it/1dz3jmk
@r_bash
how do I use mkdir -p for mkdir a and a/b and a/c and a/d? Why using -p?

Hi, Id like to learn how I should use mkdir -p for mkdir a a/b a/c a/d

I use actually mkdir -p a a/b a/c a/d

but what is the advantage of using the flag -p?

I can use the command mkdir a a/b a/c a/d without -p and get the same tree...

Thank you and regards!

https://redd.it/1dzckiu
@r_bash
Strange problem with [ -e ] on network share

Dear all

     I've a Bash noscript that checks for the existence of a file-on-a-network. The file path starts /run/user/1000/gvfs/smb-share:server=. When the file does exist, the following happens.

An initial -e check gives a false negative, i.e., it reports (by evaluating as false) that the file does not exist when it does.
A second check, carried out immediately after the first check, gives the correct result, i.e., it reports (by evaluating as true) that the file exists.

     Can anyone shed light?
     I am on 6.5 kernel, on Linux Mint Cinnamon 21.3 (which is based on Ubuntu 22.04), with Bash version '5.1.16(1)-release'.

https://redd.it/1dzzrcq
@r_bash
Ani-cli in another language.

didn't find a great place to post this, so i guess i'll ask here


i'm brazilian and would love to use ani-cli to watch anime with my brother sometimes, but he doesn't understand english. i found this which sounded like it would make ani-cli search through brazilian subbed animes but no, only english still.

does someone know how to make it work? or if there is a better substitute?

my guess is finding a lookalike with multiple languages support and hope for portuguese-brazilian being one of them, but haven't found one yet

https://redd.it/1e088yr
@r_bash
The escaping hell: can't get valid file references to pass between commands

The scenario is as follows:

I need references to the specific *mp4* files inside the subfolders of a folder. Despite being created in one shot, the modification, creation and access dates of the files don't match those of the subfolder, and these are the only parameters that can be used. To deal with this inconsistency, I set to collect the paths to the subfolders with the **find** utility and then the files with **mdfind**, directing it to each subfolder. The files are then handed over to **open** to open them with a default application.

This is a general strategy. The problem is the last step: I'm struggling with assembling the file references that would meet the acceptable escaping patterns for either a giving or receiving utility, as the filenames contain single quotes and question marks that, seemingly offend the parsers utilized by these commands. With or without xargs the shell would complain.

Here are the failed examples (I substituted **echo** for **open** in some of them temporarily):

HOST: ~login_user$ dir=$( fd ~/Movies/Downloaded\ From\ Internet/ -d 1 -type d -Btime -1d4h ) ; for f in "$dir" ; do file=$(echo "$f" | xargs -I {} mdfind -onlyin '{}' kind:"MPEG-4 movie" | sed 's/.*/"&"/') ; echo "$file" ; done


-->"/Users/login_user/Movies/Downloaded From Internet/8 levels of politeness - can you open the window/8 levels of politeness - can you open the window ? #inglese #ingles #englishingleseperitaliani #english | Aurora's Online Language Lessons | Aurora's Online Language Lessons · Original audio.mp4"
"/Users/login_user/Movies/Downloaded From Internet/Every single word? | Blackadder | BBC Comedy Greats/Every single word? | Blackadder | BBC Comedy Greats.mp4"
"/Users/login_user/Movies/Downloaded From Internet/So hard to get them right sometimes TIP The/So hard to get them right sometimes! TIP: The i of the swear words sounds like a very short é (e chiusa), whilst the other one is like our i (come in... | By Aurora's Online Language LessonsFacebook.mp4"
"/Users/login_user/Movies/Downloaded From Internet/tea #the #tee #cha #teatime #tealover #tealovers #tealife #tealove/#tea #the #tee #cha #teatime #tealover #tealovers #tealife #tealove #teezeit #british #maggiesmith | Jens Bruenger | topflixinsta · Original audio.mp4"

The files were located.

However,

HOST:~ login_user$ dir=$( fd ~/Movies/Downloaded\ From\ Internet/ -d 1 -type d -Btime -20h ) ; for f in "$dir" ; do echo "$f" | xargs -I {} mdfind -onlyin '{}' kind:"MPEG-4 movie" | sed 's/.*/"&"/' | xargs -I {} echo {} ; done

-->{}
/Users/login_user/Movies/Downloaded From Internet/Every single word? | Blackadder | BBC Comedy Greats/Every single word? | Blackadder | BBC Comedy Greats.mp4
{}
{}


HOST:~ login_user$ dir=$( fd ~/Movies/Downloaded\ From\ Internet/ -d 1 -type d -Btime -20h ) ; for f in "$dir" ; do echo "$f" | xargs -I {} mdfind -onlyin '{}' kind:"MPEG-4 movie" | sed 's/.*/"&"/' | xargs -I {} echo "{}" ; done

-->{}
/Users/login_user/Movies/Downloaded From Internet/Every single word? | Blackadder | BBC Comedy Greats/Every single word? | Blackadder | BBC Comedy Greats.mp4
{}
{}


HOST:~ login_user$ dir=$( fd ~/Movies/Downloaded\ From\ Internet/ -d 1 -type d -Btime -20h ) ; for f in "$dir" ; do echo "$f" | xargs -I {} mdfind -onlyin '{}' kind:"MPEG-4 movie" | sed "s/.*/'&'/" | xargs -I {} echo "{}" ; done

-->{}
/Users/login_user/Movies/Downloaded From Internet/Every single word? | Blackadder | BBC Comedy Greats/Every single word? | Blackadder | BBC Comedy Greats.mp4
xargs: unterminated quote



HOST:~ login_user$ dir=$( fd ~/Movies/Downloaded\ From\ Internet/ -d 1 -type d -Btime -20h ) ; for f in "$dir" ; do file=$( echo "$f" | xargs -I {} mdfind -onlyin '{}' kind:"MPEG-4 movie" | sed "s/.*/'&'/" ) ; open "$file" ; done

-->Unable to interpret ''/Users/login_user/Movies/Downloaded From Internet/8 levels of politeness - can you open the window/8
levels of politeness - can you open the window ? #inglese #ingles #englishingleseperitaliani #english | Aurora's Online Language Lessons | Aurora's Online Language Lessons · Original audio.mp4'
'/Users/login_user/Movies/Downloaded From Internet/Every single word? | Blackadder | BBC Comedy Greats/Every single word? | Blackadder | BBC Comedy Greats.mp4'
'/Users/login_user/Movies/Downloaded From Internet/So hard to get them right sometimes TIP The/So hard to get them right sometimes! TIP: The i of the swear words sounds like a very short é (e chiusa), whilst the other one is like our i (come in... | By Aurora's Online Language LessonsFacebook.mp4'
'/Users/login_user/Movies/Downloaded From Internet/tea #the #tee #cha #teatime #tealover #tealovers #tealife #tealove/#tea #the #tee #cha #teatime #tealover #tealovers #tealife #tealove #teezeit #british #maggiesmith | Jens Bruenger | topflixinsta · Original audio.mp4'' as a path or URL


I'm deadlocked.


Is there any method to reconcile them?

https://redd.it/1e0djn0
@r_bash
Autocompletions inside Gitbash

Hi, I'm a Windows user and ive recently came across git and github and gitbash, How can I get git auto completions inside the gitbash terminal, I don't want to use PowerShell or cmd , ive tried clink but i didn't find it useful, How can I get autocompletions inside gitbash

https://redd.it/1e0qmcd
@r_bash
The difference between and []

Can anyone explain to me the difference between [[ $number -ne 1 \]\] and [ $number -ne 1\] ?

https://redd.it/1e1h41q
@r_bash
Bash noscripts or functions for testing web app security

Anyone have any Bash noscripts or functions related to web app pentesting that you can share? It could be even Bash code that chains together cli tools, as long as it's related to pentesting web apps. If I use your code I'll give credit where credit is due. I'm writing a book about Bash for penetration testers.

https://redd.it/1e1l8ix
@r_bash
grep command worked in command line but not working when I use in the .shl file

grep -i "0" $DATA_HOME/fin/finalizedchecks_2024.csv > $ODU_JOBHOME/fwxcr01_stat.log
I use above grep command in the .shl noscript but it doesn't grep and save in the fwxcr01_stat.log file

https://redd.it/1e1sqml
@r_bash
Connect to SSH using the private key stored in a string instead of a file

Hello everyone,

I am trying to connect to SSH with the private key stored in a string instead of referencing a file's location. I saw a few links online, but none of them seemed to work. Can someone tell me how this can be done?

https://redd.it/1e30jjd
@r_bash
Iterate throught arbitrary range?

This noscript basically uses Kdeconnect DBUS messages to fetch specific strings from Android Notifications. But notification ID ($ITER here)is assigned almost arbitrarily. I couldnt find any CLI or DBUS messages to reset or reassign ID's. How should i iterate through them?

Thank you!


while true
do

for ITER in $(seq 1 100)
do

APPNAME=$(qdbus org.kde.kdeconnect /modules/kdeconnect/devices/${DEVID}/notifications/${ITER} org.kde.kdeconnect.device.notifications.notification.appName)

APPTITLE=$(qdbus org.kde.kdeconnect /modules/kdeconnect/devices/${DEVID}/notifications/${ITER} org.kde.kdeconnect.device.notifications.notification.noscript)

if [ "$APPNAME" = 'Tasker' ] && [ "$APPTITLE" = 'COMMAND' ]; then
echo "DISMISS ID:"$ITER "NAME:"$APPTITLE "TICKER:"$APPNAME

qdbus org.kde.kdeconnect /modules/kdeconnect/devices/${DEVID}/notifications/${ITER} org.kde.kdeconnect.device.notifications.notification.dismiss
echo "success"
exit 0

else
continue

fi
done
done



https://redd.it/1e385sc
@r_bash
How to get inline suggestions for git commands in zsh?

Hi, im new to this git and bash stuff , as a beginner in git i want autocompletion like vs code or autosuggestion(inline) like when i type "git c" it should suggest me git commit or git config , How can i do that ,im currently using zsh in my gitbash for windows and have autosuggestion plugin , installed but a problem with it is that it suggests commands from the history , if i havent used a commit or check out command it doesnt suggest it , please help

https://redd.it/1e3srh0
@r_bash
Is if [ "$1" == "" ] exactly the same as if [ -z "$1" ]?

Is if [ "$1" == "" ] exactly the same as if [ -z "$1" ]?


As someone who comes from a programming background from many other languages I find the former much easier to read, but the latter is apparently a standard in bash, so I'm wondering if there are any specific reasons it's preferred over the latter with the -z test flag?



Also, another question, is [[]] better than [] due to not needing to quote the variable and because it also allows using operators like && and || within the single [[]] block without having to create multiple [] blocks? Anything else I'm missing?

https://redd.it/1e41nq9
@r_bash
Custom Bash Prompt

Put this in your bashrc: (works best on terminals with ligatures) (bash only)

PS1='\[\e[96m\]┌[\[\e[91;1;3m\]\u\[\e[0;93m\]@\[\e[94m\]\h\[\e[96m\]]-[\[\e[92m\]\w\[\e[96m\]]\n└─\[\e[92m\]~>\[\e[0m\] '

https://redd.it/1e43bwj
@r_bash
The writings on the wall
https://redd.it/1e4fez6
@r_bash