r_bash – Telegram
Compare two folders and output the filename as well as a checkbox or boolean for the columns present and not present in a csv file

Compare two folders and output the filename as well as a checkbox or boolean for the columns present and not present in a csv file. Trying to see how to pipe the content of a folder and then make a 2d array and then output it to a csv file using bash.

https://redd.it/10wl0p7
@r_bash
Using variables for storing default values for other variables

Hi! I literally have the following piece of code for setting variable if it's unset:

declare SUMMARYDESCRIPTIONPREFIX="${SUMMARYDESCRIPTIONPREFIX-Denoscription: }"

and hundreds lines later:

SUMMARYDESCRIPTIONPREFIX="$(yq '.summary.denoscription.prefix // "Denoscription: "' "$themetoset")"

to load variable value from file. What bothers me - that default value is duplicated twice. It's error prone and furthermore requires find and change things more than I want. What I want to do: to write something like this:

declare SUMMARYDESCRIPTIONPREFIX="${SUMMARYDESCRIPTIONPREFIX-$VARIABLEWITHDEFAULT}"

and:

SUMMARYDESCRIPTIONPREFIX="$(yq '.summary.denoscription.prefix // "$VARIABLEWITHDEFAULT"' "$themetoset")"

How do I do such thing for the first code line? Bash doesn't recognize $VARIABLE_WITH_DEFAULT as a variable in the expansion context.

I've tried the following thing:

getordefault() { declare -n name="$1"; declare default="$2"; if [ -v "$name" ]; then echo -n "$name"; else echo "$default"; fi; }

but it turns out that for the set but empty variable it will the provided default value.

https://redd.it/10wobbx
@r_bash
Need advice on file searching and filtering in subfolders

I have a folder that contain multiple-level subfolders, inside those subfolders may contain different srt file with ending "\_vi.srt" and "\_vi\_x.srt" (x from 1-9). The filename part are matched with its subfolder name but may contain spaces. It looks like below:

In subfolder named "Hello World":

* Hello Word\_vi.srt
* Hello Word\_vi\_1.srt
* Hello Word\_vi\_2.srt

In other subfolder named "Hello Reddit":

* Hello Reddit\_vi.srt
* Hello Reddit\_vi\_1.srt
* Hello Reddit\_vi\_2.srt
* Hello Reddit\_vi\_3.srt

And I have about 30-40 subfolders like above.

I want to checked for srt file with highest x in each subfolder and replace it to the one without x ("\_vi.srt").

Below is my noscript for checking in a specific folder but I'm still finding the way to achieve it in multiple-level subfolders:

#!/bin/sh

folder="Source"
srt_files=($folder/*_vi_*.srt)

if [ ${#srt_files[@]} -gt 0 ]; then
max_index=0
for i in "${!srt_files[@]}"; do
x=$(echo "${srt_files[$i]}" | grep -o "_vi_[0-9]*" | sed 's/_vi_//')
if [ "$x" -eq "$x" ] 2>/dev/null && [ "$x" -gt "$max_index" ]; then
max_index="$x"
max_file="${srt_files[$i]}"
fi
done

if [ -n "$max_file" ]; then
vi_file="${max_file%_vi_*}_vi.srt"
mv "$max_file" "$vi_file"
echo "Lastest SRT Version: $(basename "$max_file")"
echo "Replaced to: $(basename "$vi_file")"

fi
fi

Any advice is really appreciated!!!

Thank you.

https://redd.it/10wptye
@r_bash
Why does 1> create a file but >1 does not?

When using output redirection, 1> creates the output file if it does not exist but >1 does not. Is there a reason for this? Am I mistaken when I think that 1> and >1 are the same thing?

https://redd.it/10x99ot
@r_bash
Compare two folders and output the filename as well as a boolean and put the data inside a csv file

I need two columns, one named filename and the other called present in both folders. How do you do this? I heard 2d arrays are not possible in bash, but that we can simulate it somehow. How?

https://redd.it/10xgipr
@r_bash
expr called by echo doesn't evaluate anything

So I tried this example here:

#!/bin/bash
read -p "Enter first number: " v1
read -p "Enter second number: " v2
res='expr $v1 + $v2'
echo "Sum is : $res"

Output:

user@user:~/Desktop$ bash bash.sh
Enter first number: 2
Enter second number: 3
Sum is : expr $v1 + $v2

What's wrong? Tried res="expr $v1 + v2" didn't work

https://redd.it/10xmgs8
@r_bash
Why is this curl command giving me error?

Using the exact example command from API documentation just replacing username and password.. it throws error saying URL using bad/illegal format or missing URL. What am I missing here? Does this command not work on mac systems?


curl --location -g --request GET 'https://dashboard.api.pixalate.com/services/2022/Report/getDetails?username=user&password=password123&timeZone=0&start=0&limit=20&q=fraudType,impressions,sivtImpressions,sivtImpsRate,givtImpressions,givtImpsRate WHERE day>='\''2020-09-01'\'' AND day<='\''2020-09-10'\'' GROUP BY fraudType ORDER BY impressions DESC'

https://redd.it/10y2i33
@r_bash
what is the correct way to show follow a symlink while showing hidden files?

I am trying to fix up my noscript [published a couple of days ago](https://github.com/robss2020/rmdryrun), to correctly follow symlinks and hidden files.

What do you think [about this version that may support symlinks and hidden files](https://hastebin.com/share/ujefixojod.bash)?

I'm not 100% sure what the desired functionality is with respect to following or not following hidden files and symlinks. Right now if you list the hidden file explicitly (by giving it, rather than matching it with *) it will list it.

Let me know what you think!

https://redd.it/10y90it
@r_bash
Where to install config files?

I'm writing an install noscript so when someone inexperienced downloads one of my noscripts they can run the install.sh noscript to set everything up for them.

At first I wrote it to create $HOME/bin and $HOME/bin/config folders (if they didn't exist). But some of my noscripts are written for Synology NAS devices and I remembered that on a Synology you can disable home folders. So I changed my install noscript to check if the $HOME folder exists, and if not then install the noscript in /etc/local/bin. But the config file and exclude files (for tar and rysnc) need to easily accessible and editable by inexperienced users.

Where should extra files that a noscript needs normally be installed?

If you want to see, and critique, what I've written so far it's here: https://gist.github.com/007revad/8df1075b6a67168e1c2e9042de42885b

https://redd.it/10ycc31
@r_bash
can someone help me be able to send a zenity window to a logged in user?

I feel like I have tried every combo of modifying the DISPLAY variable but cannot get the window to pop up for that user.

Does anyone have a trick or a way to send a zenity (or equivalent) window to a logged in user.

https://redd.it/10yehfn
@r_bash
is that can be done beneath only bash noscript ?

goal is

entering(editing) multiple text files (10s+) and exchange a specific line 'a line that exist in whole given text files exactly the same' exchange this line as it's few words ..exchange it to a given new line 'words' that will be in putted with 'read' as input from user 'user is me' , to change that word to anew given word for those multiple text files as only one time by doing such a noscript ? that can be only inside a bash noscript ?

https://redd.it/10ygj3q
@r_bash
identification of duplicate files within folders AND archives

I purposefully changed this from deduplication as, normally, files within zips are there for a reason, but I have stacks of zip files, and extracted zip files (yah know how lazy it is to extract but keep the zip for posterity).

I'm interested in a noscript that will generate sha1 all files within an folder of all files AND archives (gz,xy,zip,rar,7z) and output path and checksum to a text file, then another which will either identify duplicates or remove unique SHA1 checksums leaving me with a curated list of files which I can go through.

Has anyone done anything similar to this before pls ?

https://redd.it/10yq5kg
@r_bash
printing from background

I have multiple tasks that run in the background. They are detached with nohup and &

I would like to print a message to stdout when i am done. (This code is part of a "multithreading"-noscript that allows me to run multiple instances of a command easily)


what i have currently is the following:

$command &>> log.txt &

&#x200B;

Just adding an echo does not work:

$command &>> log.txt && echo "$command: success!"

I would have to wait for $command to finish, which breaks my noscript. Can i print to the foreground shell from a background task?

https://redd.it/10yvxcq
@r_bash
Testing an unset variable returns true... always?

Running into some unexpected behavior. When testing if an unset variable is empty/non-empty, it always returns true.

I'm seeing the following:
$ echo ${TEST}

$ test -z ${TEST}; echo $?
0
$ test -n ${TEST}; echo $?
0


This also happens using if [ ... ] as well. This happens when the variable is set to an empty string too (TEST='')

Tested this on rhel 8 and ubuntu 22.04, is this expected behavior? I am confused.

https://redd.it/10yylr4
@r_bash
how to find files, rename and move then

How can I achieve this?
I tried something like
find . -name *.txt | sed 's%\(path\)\(filename\).txt%\1\2.data' but that only changes the name/extension of the found file. Moving the file is only possible when I have the original name and the new one.

https://redd.it/10yzfs9
@r_bash
Question for bash expert

Hi everyone

I'm using a tool in CLI that requires one fila as argument: mycommand -f file.yaml

I would like to call this command in one line but with a "file" result of 2 other files merge.

It would have been:
$ cat file1.yaml file2.yaml > merged.yaml
$ my
command -f merged.yaml

I used sometimes the triple < for input, like
$ jq . <<< ${contentInJson}
but I don't know how to use it in var as input/var

Does someone know a way to achieve that?

Thanks

https://redd.it/10zjtxl
@r_bash
What is bash written in?

I googled it and it says C, but when I open up a bash command it doesn't look like C. It looks like the following.

&#x200B;

^B^@^B^O<84>MÿÿÿH<8b>-Ä ^B^@H<85>í^O<84>@ÿÿÿH»ÿÿÿÿÿÿÿ^H!ëH9ÝubL<8d>$í^@^@^@^@L<89>çèÑGÿÿH<89>^Eâ^^^B^@H<89>ÇH<85>ÀtCH<8b>^U<8b>^^^B^@H<89>Áë^NH<89>^QH<8b><92>°^@^@^@H<83>Á^HH<85>ÒuíH<89>îH<8d>^MÉÄÿÿº^H^@^@^@èÏDÿÿH<8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8b>5^C^\^B^@H<8b>=^D^\^B^@è§Dÿÿ<85>À^O<84>^F^O^@^@<83>=d^G^B^@^A^O<84>^[^D^@^@<83>=Ã^\^B^@^@^O<85>^X^D^@^@L<8d>sèHÇD$^X^@^@^@^@H<8b>=Ñ^[^B^@1ÒL<89>öèwEÿÿA<89>Ç<85>À^O<85>u


what is this, I am looking to make a tui in python that reads bash commands from usr/bin and walks me through the command.

[https://redd.it/10znnly

@r_bash
gh-f adds diff per filetype and other small improvements

gh-f is a GitHub CLI extension that I wrote that does all-things-fzf for git. From time to time I add new small features or quality of life adjustments :).

Latest I added the possibility to diff, add and checkout filetypes based on extension only, see below:

&#x200B;

https://i.redd.it/sa5w25fdglha1.gif

together with support for git environment variables and other minor fixes to cherry pick files and branches. There are many more features available as shown in the gif: hop by and have a look!

Link to the repository

https://redd.it/10zsubv
@r_bash
Bash/programming community

Are there any good programming forums that is active with discussions etc, not the stackoverflow page but some other?

I have a task im stuck on and in need for some help in my noscript

Appreciate any answers :)

https://redd.it/10zumn2
@r_bash