r_bash – Telegram
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
Custom bash prompt turned into launcher

I initially put this as a reply to a previous thread but it did not go where I wanted, so here it is instead for what it is worth.

I currently have about 800 aliases in 35 bashrc-xxx files pointing to various folders, noscripts and programs.

Gdrive link: https://drive.google.com/drive/folders/1hTfNvUvI9zRla9nB6WhEyQa2EmGfd\_ol?usp=drive\_link

My goal is to have a generic launcher that will work on any linux distro using bash. Just double click on an alias to copy then paste and enter.

I like the ability to view many aliases without scrolling.

Vektor

https://redd.it/1e4ovv1
@r_bash
Bash completion for a "passthrough" Git command?

I have a simple git extension that I use to set the global gitconfig at execution time. It has a few subcommands of its own, but the main use case is for commands that take the form

```
git profile PROFILE_NAME [git-command] [git-command-args]
```

This particular execution path is really just an alias for

```
GIT_CONFIG_GLOBAL=/path/to/PROFILE-NAME/config git PROFILE_NAME [git-command] [git-command-args]
```

Easy enough.

The hard part is Bash completion. If "$2" is a profile name, then the remaining args should simply be forwarded on to Git. I'm using the completions provided by the Git project (cf. [here](https://github.com/git/git/blob/5dd5007f8936f8d37cf95119e83039bd9237a3c5/contrib/completion/git-completion.bash)), and I don't fully grok the code therein but my understanding is that the entry point to wrap the Git command itself from within another completion routing (i.e., not just calling `complete`) is `__git_func_wrap __git_main`.

Hence my intended approach would be something like this. (Note: I'm aware that this completion currently only supports invocations of the form `git <plugin-name>` syntax, not the single-word `git-<plugin-name>`. Not bugged for the moment.)

_git_profile() {
local -r cur="${COMP_WORDS[COMP_CWORD]}"

local -ar profiles=("$(___git_profile_get_profiles "$cur")")
local -ar subcmds=("$(___git_profile_get_subcmds "$cur")")
local -ar word_opts=("${profiles[@]}" "${subcmds[@]}")

case $COMP_CWORD in
1) ;;
2)
__gitcomp "${word_opts[*]}"
;;
*)
local profile_arg=${COMP_WORDS[2]}

# Has the user specified a subcommand supported directly by this plugin?
# All our subcommands currently don't accept args, so bail out here
if ! _git_profile_arg_in "$profile_arg" "${subcmds[@]}"; then
return
fi

# Have they instead specified a config profile?
if ! _git_profile_arg_in "$profile_arg" "${profiles[@]}"; then
return
fi

local -r profile="$profile_arg"
local -r cmd_suffix="-profile"

COMP_WORDS=('git' "${COMP_WORDS[@]:3}")
COMP_LINE="${COMP_WORDS[*]}"
COMP_CWORD=$((COMP_CWORD - 2))
COMP_POINT=$((COMP_POINT - ${#profile} - ${#cmd_suffix} - 1)) # -1 for the space between $1 and $2
GIT_CONFIG_GLOBAL="${GIT_PROFILE_CONFIG_HOME:-${HOME}/.config/git/profiles%/}/${profile}" \
__git_func_wrap __git_main
;;
esac
}


Tl;dr:

* Grab the one arg we care about.
* If it's a subcommand of my noscript, nothing left to do.
* If it's not a known config profile, nothing left to do.
* If it *is* a known profile, then rebuild the command line to be parsed by Git completion such that it reads `git [git-command] [git-command-args]` from Git's point of view (with the caveat that it will use the specified custom config for any commands that read from or write to global config).

When I enter `git` into a terminal and press <TAB> twice, with this completion included in `$HOME/.local/share/bash-completions/`:

* `profile` is populated as a Git subcommand and can be autocompleted from partial segments (e.g., `git p`)

When I enter `git profile` and press <TAB> twice:

* all subcommands supported by the noscript and config profile directories are listed and can be autocompleted from partial segments (e.g., `git a` + <TAB> twice offers the 'add' command and the 'aaaaa' profile as completion options)

When I enter `git profile aaaaa`, where `aaaaa` is a Git config profile and press <TAB> twice:

* a long list of what appear to be all known Git commands is listed (including `profile`, but I'll solve that another day)
* when subsequently typing any character, whether or not it is the first letter of any known Git commands, and then pressing <TAB> twice, no completion options are offered
* This includes hypens, so I don't get completion for any top-level options

This is where the problem arises. I've found an entry point to expose available Git commands, but
either there are subsequent steps required to expose additional completions and support partial command words via the `__git_func_wrap` approach, or `__git_func_wrap` is the wrong entry point.

I've experimented with a few additional functions, such as `__gitcomp` inside of the function`, and using __gitcomplete` and the triple-underscored `___gitcomplete` as invocations in the completion noscript (outside of the function). To use `__gitcomp` correctly seems to entail that I'd have to simply reimplement support for most or all Git commands, and as I understand it, nothing like `__gitcomplete` should need to be invoked for a noscript named according to the `git-cmd` syntax. Basically, I'm un-systematically trying functions that look like they address the use case, because I'm not totally clear *what* the correct approach is here.

Any insight anyone can offer is appreciated. Not looking for a comprehensive solution, just a nudge in the right direction, including a better TFM than the completion code itself is possible. (Fwiw, I'm familiar with the general Bash completion docs.)

https://redd.it/1e4r2k5
@r_bash
Stuck trying to get a find cmd to echo No File Found when a file is not found

for SOURCE in "${SOURCES@}"; do

## Set file path
FILEPATH="${ORIGIN}/${SOURCE}/EIB/"

echo " "
echo "Searching for ${SOURCE} file..."
echo " "

FILES
FOUND=()

find "${FILEPATH}" -type f -print0 | while IFS= read -r -d '' file; do
FILES
FOUND+=("$file")
FILENAME=$(basename "$file")
echo "THIS WOULD BE WHERE THE SCRIPT CP FILE"
done
if ${#FILES_FOUND[@} -eq 0 ]; then
echo "No File Found in ${FILEPATH}"
continue
if
done




I have tried a couple ways to do this, setting FILES\
FOUND to false and then true inside the while loop, using the array(seen in the code above), moving the if statement inside the while loop. The latter didn't out out No File Found when a file was found, the other ways put No File Found when a file was found.

Since the while loop is creating a subshell, the variable that is being set outside it I don't think is being updated correctly


https://redd.it/1e4t4vm
@r_bash