r_bash – Telegram
Having trouble saving full sub directory names

I'm trying to save the folder name of sub directories, for example I want to store "long folder name" in x/folder/long folder name, but from folders with multiple words I'm only getting the first word and I can't figure out how to get the whole thing.

The whole thing does print when I just run the command in terminal though.

$ find . -type d -maxdepth 2 -mindepth 2
./folder/Apple Banana

Script:

#!/bin/bash
set -x

for directory in find . -type d -maxdepth 2 -mindepth 2
do
echo "$directory" exists here - do something with it
done

Output:

+ for directory in find . -type d -maxdepth 2 -mindepth 2
+ echo ./folder/Apple exists here - do something with it
./folder/Apple exists here - do something with it
+ for directory in find . -type d -maxdepth 2 -mindepth 2
+ echo Banana exists here - do something with it
Banana exists here - do something with it

Single word folders print as expected:

+ for directory in find . -type d -maxdepth 2 -mindepth 2
+ echo ./aaa/bbb exists here - do something with it
./aaa/bbb exists here - do something with it

https://redd.it/y3w2t2
@r_bash
GUI Sudo Password Prompto for launching Applications as root?

How does one prompt the GUI sudo password window to launch applications such as xed without launching a terminal window.

I want to create a launcher which will launched xed as root and be able to edit some files from XAMPP to allow me to do modify my XAMPP virtual hosts.

pkexec xed /etc/hosts /opt/lampp/etc/extra/httpd-vhosts.conf /opt/lampp/etc/httpd.conf

https://redd.it/y4ays3
@r_bash
What is the asterisk between the patterns, in Grep AND using -E?

grep -E 'pattern1.*pattern2' filename

I know this command should bring `pattern1` and `pattern2` in the file `filename`.

But what is the asterisk in the second pattern and not the first one, and what is its usage?

https://redd.it/y4pwh5
@r_bash
Is it possible to handle a command before it's passed to the bash command parser?

I'm not sure how to word the question correctly, so ill try to explain.

When you want to increment an integer, you have to do

NUMBER=$((NUMBER + 1))

I'm wanting to simplify this by doing what other languages do, which would be

NUMBER++

Is there something that I can make that looks through all the input before it's executed by bash? Because I know that I could just make a command and pass it in as an argument like

math NUMBER++

But id like this to be simpler than that.

​

Sorry if this sounds weird. I'm not sure how bash handles commands, so I'm just going off of what I assume happens.

https://redd.it/y51b3q
@r_bash
Confusion with Bash and Z shell

Hi!

So I'm trying to install flutter on my macOS Monterey. When I first ran the command in terminal to see what shell I have it told me bash. I had some trouble finding the .bashrc file but eventually I was able to find it and make the necessary changes. But when I tried to run flutter in terminal it would not let me. Now when I run the command to see what shell I have it's telling me zsh. So I tried opening the .zshrc file in textedit to input path of my flutter git repo but it keeps telling me that I do not have permission to make changes to it. Does anyone know how I can fix this?

https://redd.it/y5owuv
@r_bash
What's the best way to localize (for different languages and locales) bash terminal apps?

Just wondering what a good solution to localize an existing app might be, with string text embedded in the noscripts. Refactoring isn't an obstacle (and eventual translation of text blocks), but what options are there in terms of libraries to achieve this. Thanks.

https://redd.it/y5rp0a
@r_bash
Using a bash noscript to streamline GitHub Actions

Using a bash noscript (based on bashew framework) to centralize the GitHub Action setup (e.g. pip install), Action payload and Action wrap-up (commit/push the results) in one place, so that the Action config YML becomes this simple:

- name: gha:before
run: |
./bashewgithubaction.sh gha:before
- name: gha:execute
run: |
./bashewgithubaction.sh gha:execute
- name: gha:after
run: |-
./bashewgithubaction.sh gha:after

Advantages:

Single Responsibility. You edit your setup code in the same file as the payload or the wrap-up code. You don’t touch the `action.yml` file anymore after initial setup.
Cleaner Code. The YML syntax forces you to a do this && do that && do the other
one-liner format. A bash noscript allows you to do if/then, for/do, while/do, recursion … in an easy and clean way.
Easy Debugging. `bashew` has built-in support for log files and optional verbose mode. It also cleans up log files after 30 days, so they don’t clog up your repo.
Self-Contained. You don’t need external libraries or runtimes. bash runs on most Action Runners (Linux/MacOS) and each bashew noscript contains the entire framework.

More details on blog.forret.com

https://redd.it/y5t8me
@r_bash
inline noscript runs as expected, however not when read from file

I am at a loss here. I write my code inline and it just works. Then I transfer the code into a .sh file and it no longer does.

I am in a directory /foo/bar and there is a subdirectory present named cfg

while true; do { if -d ./cfg ; then cd ./cfg/; break; fi; } done

Running this, it changes into the director cfg as expected. However after transferring it to a file:

1 #!/bin/bash
2
3 while true; do
4 {
5 if -d ./cfg ; then
6 cd ./cfg/; else
7 break;
8 fi;
9 }
10 done

it does nothing, outputs no errors and merely rests in the directory /foo/bar.

Any tips would be appreciated


Edit: Obviously it works fine while being run in the same shell with source noscript.sh . However I am looking for a way that it executes without the source command.

https://redd.it/y64byl
@r_bash
Suggest courses for learning bash

Hi , im very new to using bash. I know basic commands in terminal such as ls , cd , mkdir , vi editor , chmod .
I was to be able to use if conditions and awk ,sed and regular expression more flexibly since that would make my work alot more easier . Can anyone suggest a site to learn them ?

https://redd.it/y66ij2
@r_bash
Curl sse streaming output in a do loop input

I am trying to figure out how to use Curl output in a loop.

while IFS= read -r linestream
do
//Some logic
done < $(curl https://some.url)

The source URL is a Server Side Event, which constantly streams data. The problem is that Curl is outputting the progress bar. How do I feed the standard output to the loop instead of the apparently standard error?

&#x200B;

Edit: Typo in the tile while instead of do

https://redd.it/y6a8sx
@r_bash
Add trailing slashes to all arguments for rsync

Hi,

I’m using the following function to rsync a ton of media from one location to another:

nsync () {

sdir=“${1%/}/”
ddir=“${2%/}/”
command rsync -avvhP --remove-source-files “$sdir” “$ddir”

}

I’m trying to change this so that I can add multiple source directories and adding a trailing slash to them all (technically it wouldn’t matter whether the destination dir has a slash), but I’m not sure how to set this up to handle an unknown amount of source directories, most likely between 2 and 6, but really not sure. I’m assuming I’d need to loop through all the arguments, which I can do, but I’m not sure how I could get a variable for each one, name it, and have it included in the rsync command.

Any help would be appreciated.

Thank you!

https://redd.it/y6mhzi
@r_bash
Automating ssh using a file with IP addresses

I am trying to automate sending commands to machines in a local cluster. I have the IPs saved in a file and I am using this noscript to simply make a file on the Desktop. See below:

#!bin/bash
input="/home/user/Desktop/deploy/IPs.txt"
while read -r line
do
echo "connecting to $line"
sshpass -pPASSWORD ssh remoteUser@$line mkdir ~/Desktop/folder || echo "error occured on IP:$line"
echo "$line setup!"
done < "$input"

This however, only works for the first IP listed in the file and then quits before doing the same thing for all the other IPs. Why does this happen and how can I fix it?

https://redd.it/y6nah9
@r_bash
help: delete largest duplicate file

Hi everyone, I'm struggling with a little bash noscript this morning and while I often like to experiment and find it myself, I'm stuck.

I have a directory that contains about 1k video files. Each file is duplicated and have different encodings and frame sizes. Since it's for archival I only want to keep the smallest file for each video.

Both duplicates of a file have the same name until the last 16 characters which are a random string of characters/timestamp. And the extensions are inconsistent.

I can list all files, ordered by name which places the duplicates next to each other, but then how do i find the one with the largest filesize and delete that one?
Also i can't just go though the list 2 by 2 because not 100% of the files have a duplicate. But I can't think of another way to traverse the file list with my current skillset.

I'm a beginner at bash, have only written 4-5 complex noscripts and that was while constantly looking at basic documentation just to get a ''if statement'' syntax right. So any help would be greatly appreciated.

https://redd.it/y70r7j
@r_bash
Bash help

I need urgent help with bash for an upcoming assessment. I usually wouldn't ask help but I've no clue how bash works. If anyone can help please dm

https://redd.it/y753m9
@r_bash
Problem with handling with datetimes in Bash

I'm quite new to bash noscripting, and test in general. I'm writing a noscript to automatically update Docker images, when I get this error:

/home/misery/update-images.sh: line 31: [[: 2022-10-07T02: value too great for base (error token is "07T02")


Before I call test, I logged the timestamp I extract from the Docker API:
Remote image created on 2022-10-07T02:22:37
^^^^^^^^^^^^^^^^^^^
In a variable called 'remoteImage'


For debugging purposes, I tried echoing localImage too:
"2022-10-07T02:22:37


Yet why am I getting an error in line 31?

Here's the code where I do an if
if [[ "$remoteImage" -eq "${localImage:1}" ]]; then
echo $image is outdated!
else
echo $image is up-to-date
fi


https://redd.it/y78wln
@r_bash
What is this local and where I can learn more

Is this maybe obsolete?




pause(){

local message="$@"

[ -z $message ] && message="Press Enter key to continue..."


read -p "$message" readEnterKey
}

https://redd.it/y7afy6
@r_bash
Newbie question, How do I convert a string to numeric

For example.

$username =?

Im trying to give each user a UID that matches to the numaric value of its name.

Any help will be appricated

https://redd.it/y7e7uo
@r_bash