r_bash – Telegram
Any recommendation on how I can automate typing on screen?

Any apps allow typing, open tab, automation?

Obviously we can send api commands for adb but need to use different commands on other tabs

OS Ubuntu 18

https://redd.it/yp8wx8
@r_bash
How can I pass array elements (strings) to cURL properly?

I'm trying to pass array elements to curl but getting the following error instead:

curl: (3) URL using bad/illegal format or missing URL

The current format of strings inside the array is a product of tons of manipulation attempts, to no avail yet. It's funny that e.g. a similar command f=$(echo "$file") returns the strings as necessary, plus running each string (without double quotes) in the terminal by appending to curl -L works well too.

Thank you!

https://redd.it/ypcfqm
@r_bash
One of commands in my bash noscript is not executed.

Hi,

I have a little problem with creating a bash noscript. The second line with wmctrl command for some reason is not executed. What am I doing wrong?

#!/bin/bash
zenity --info --noscript="Job" --text="The demo noscript is now complete."
wmctrl -r Job -b add,above

​

https://preview.redd.it/jhic2m9umpy91.png?width=1308&format=png&auto=webp&s=e03c3ea3927a6c715597882aa186c44512bcc68d

https://redd.it/ypiyv9
@r_bash
Int or Str

I'm writing a noscript that read param and says if it is integer or string. My idea is to compare $param + 0 and $param. Here is my noscript:

#! /bin/bash
read param
if "$param" + 0 == "$param"
then
echo Integer
else
echo String
fi

It always returns:

./intorstr.sh: line 3: : too many arguments
String

Any ideas, what's wrong here?

[https://redd.it/ypqtsh

@r_bash
how do I write this assigning output line 3 from a list?

LIST=(a b c d e f g h)
LSA="ls"
fruit=($(LSA -la | sed -d '3p'))

Tried and receiving error. How can I fix this? Is having space between LSA -la the issue here?

https://redd.it/ypuytd
@r_bash
Karenified/Sarcastic Text

# karenify.sh

> Have you ever wanted to "karenify" some text, lIkE tHiS, but don't want to spend the time manually casing each character?

So, anyway, I started writing this out quite a while ago, but it never was quite performant enough to share...and beyond janky. Its still janky, but I think its fast "enough" for the moment (more on that later).

Oh, and a small preface that in the below examples, I've added ~/.local/bin/karenify -> ~/noscripts/tools/karenify.sh to $PATH...

## Usage

Originally I had intended $* to be an input, but decided against it for now. This means I can assume you'll be trying to karenify a file or stdin only -- so heredocs/strings work fine, too:

karenify example.txt
printf '%s\n' "foo bar" | karenify
karenify <<- EOF
foo bar
EOF
karenify <<< "foo bar"

The default casing mode will produce aBc casing across all lines. To use AbC casing, include the [-i|--invert] flag

# fOo BaR
karenify <<< "foo bar"

#FoO bAr
karenify -i <<< "foo bar"
karenify --invert <<< "foo bar"

I've also included an implementation in gawk, mostly for comparing speed against builtins. So far, I've found that the builtin implementation appears to be just slightly faster with short text (a few lines); but the gawk variant is faster processing larger files. To use this, you'd just need to include the [-a|--awk] flag

# fOo BaR
karenify -a <<< "foo bar"

#FoO bAr
karenify -ai <<< "foo bar"
karenify --awk --invert <<< "foo bar"

## Basic Speed Test

And by "basic", I mean with time. Testing (and writing) done within a WSL2 Ubuntu environment (20.04.5 LTS).

### Herestring

Command | Real | User | Sys
--------|------|------|------
karenify <<< "foo bar" | 0.004s | 0.004s | 0.000s
karenify -a <<< "foo bar" | 0.005s | 0.006s | 0.000s
karenify -i <<< "foo bar" | 0.004s | 0.002s | 0.003s
karenify -ai <<< "foo bar" | 0.005s | 0.005s | 0.001s

### karenify.sh

Command | Real | User | Sys
--------|------------|------|------|------
karenify ./karenify.sh | 0.052s | 0.042s | 0.010s
karenify -a ./karenify.sh | 0.008s | 0.004s | 0.004s
karenify -i ./karenify.sh | 0.051s | 0.051s | 0.00s
karenify -ai ./karenify.sh | 0.008s | 0.007s | 0.001s

## Language Support

I'm an english-only speaker, so karenify will only check for [a-zA-Z] and case accordingly. I'm not opposed to supporting other languages, I'm just unsure how to do so in a sensible way with the current implementations.

## Repository

I may eventually break my tools out to their own location, but for now you can find karenify (along with my other tools/configs) in my dotfiles repo.

## Feedback

I'm more than happy to hear feedback, especially suggestions to further increase the speed in either the builtin or gawk implementations -- I'm sure the builtin could be faster, but I'm not sure of a good way to do that.

https://redd.it/ypydm1
@r_bash
Complete beginner hoping to convert a .BAT to a BASH.SH

First of all, I hope this is an appropriate place for a question like this. If it's not, please lock!

I work in a science lab and our microscope takes pictures in a particular way. Basically, it outputs a bunch of image files that must be stitched together with a python program in order to form a really high resolution TIFF (thousands of them, actually...)

We have a .bat file that works great on our Windows machines. But we'd love to be able to process the images on our Macs and our Ubuntus as well.

Here's the Windows .bat noscript:


>:: Locations of things
>::

>set TERASTITCHER=C:\terastitcher\terastitcher

>set Parastitcher=C:\terastitcher\Parastitcher3.2.2.py


>:: Set active directory to path of batch file parent folder

>cd /d %~dp0

>SET WORKINGDIR=%CD%

>for %% in (.) do SET DIRNAME=%%~n

>SET OUTPUTDIR=%DIRNAME%stitched

>mkdir "..\%OUTPUTDIR%"



If you drag the .bat file into the parent folder containing the unstitched images, you can double-click it and it will start the stitching process, creating a new folder with '
stitched' appended to the directory name.

Could that same process be more or less replicated for use with macOS/Linux?

I know this is probably kindergarten level noscripting, but I did try and fail to figure it out on my own before posting here. Any advice would be greatly appreciated and might even speed up some scientific discoveries! ;)

https://redd.it/yqghsc
@r_bash
Can, uh, someone explain to me how in the hell this environment variable is hiding text and displaying extra information in some contexts? Does `git log` do some crazy magic?
https://redd.it/yqv5pj
@r_bash
new user trying to learn what am i doing wrong?

# This is just a bit of fun between friends but what am i doing wrong ? I'm following a book I just can't figure it out.

**Meganoob BE KIND**

what am I doing wrong? im reading unix in 24 hrs fifth edition Task 16.1: shell variables

I am trying to have the output say Nathan is a grass. after the word Nathan is typed

here is how I've tried so far.

Attempt three

\#!/bin/bash

$attitude {basically a grass}

$echo 'Nathan is $attitude

done

done

error message

./3.sh: line 2: {basically: command not found

./3.sh: line 3: Nathan: command not found

./3.sh: line 4: syntax error near unexpected token `done'

./3.sh: line 4: `done'

Attempt two

GNU nano 6.2 2.sh

\#!/bin/bash

$leaning='basically a grass'

$echo 'Nathan is{$leaning}

Error message

./2.sh: line 2: =basically a grass: command not found

./2.sh: line 3: unexpected EOF while looking for matching `''

./2.sh: line 5: syntax error: unexpected end of file

Attempt one

\#!/bin/bash

$echo 'Nathan is ${attitude}

${attitude} 'basically a grass'

error message

./1.sh: line 4: unexpected EOF while looking for matching `''

./1.sh: line 6: syntax error: unexpected end of file

I am trying to write Nathan and have it autocomplete is a grass. it's just a bit of fun between friends but i believe i am following the book Sams teach your self Unix in 24 hours fifth edition page 314 Task 16.1

Any help would be appreciated and gratefully received.

I am using Linux Mint 21

https://redd.it/yqwx08
@r_bash
Having trouble getting this line to work. Any help would be most appreciated!

Trying to convert some recordings of speech into text. Found this via search and I've been messing with it for a while now and can't seem to get it to work.

wget -q -U “Mozilla/5.0” –post-file file.flac –header “Content-Type: audio/x-flac; rate=16000” -O – “http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium” | cut -d” -f12 >stt.txt

Any suggestions?

https://redd.it/yqvn6l
@r_bash
git fetch --dry-run

yoo... so how can check "git fetch --dry-run" for the word "master" grep seems to not work. ive tried a bunch of things.... :(

```
#if [[ $(git fetch --dry-run) =~ *"master"* ]]; then
# echo "master found"
#else
# echo "master not found"
#fi

#if [[ $(git fetch --dry-run | grep 'master') ]]; then
# echo found
#fi

#if [[ $(git fetch --dry-run 2>/dev/null | grep "master") ]]; then
echo "YESSSSSSSSSS"
#else
echo "fuck"
#fi
```
It works for "git status" I can grep the word "behind" from the output but I need to work with "git fetch". I dont even care if its "grep" command used I just need to "do something" *if "git fetch --dry-run" retuns "master" in output...

can i haz halp plz

https://redd.it/yr5yyg
@r_bash
How to use if statement with sed editor

Hello!

I Have a noscript:

#!/bin/bash
sed -E 's/(^,,([^,]),) ?(([:alpha:])^ +)(([^,]),^,,)[^,]/\1\u\3\u\5\L\4\6\2@example.com/' file.csv > output.csv

which parse my csv file, with structure:

id,locationid,name,noscript,email,directorate
1,1,Amy Lee,Singer,,,
2,2,brad
Pitt,Actor,pitty@example.com,Production
3,5,steven spielberg,Producer,Screenwriter,
spielberg@example.com,Production
4,8,andy lee,Comedian,,Radio

It needs to be structured like this:

id,location
id,name,noscript,email,directorate
1,1,Amy Lee,Singer,alee1@example.com,,
2,2,Brad Pitt,Actor,bpitt@example.com,Production
3,5,Steven Spielberg,Producer,Screenwriter, sspielberg@example.com,Production
4,8,Andy Lee,Comedian,alee8@example.com,Radio

My noscript almost do it, except:

1. he cut values in noscript column, because I have the comma, example Producer,Screenwriter, need to save full noscript
2. email construction should be first letter of first name + last name + abc.com. If there are duplicate emails (Amy Lee and Andy Lee will be alee) need to add location\_id, and construction will be - first letter of first name + last name + location_d + abc.com

Any one can help me? I broke my whole head to solve this problem. Perhaps there is a simpler solution?

https://redd.it/yrfasz
@r_bash
Strange bug bash + python + i3blocks

I'm posting here even if it's i3 related because I feel in the guts I'm doing something wrong in Bash and all this happens inside a .sh file, thus I suppose I'll find my answer here.

I'm trying to update an i3blocks bar using a Python noscript that returns a value inside a Bash noscript by doing so:WEATHER_COLOR=$(python temp_color.py ${WEATHER_ROUNDED} | xargs echo)

I don't know if that xargs echo is necessary, I appended it to "force" the echoing of the result because I thought it was a formatting problem.

Then I pass it to:

echo -e "<span color='${WEATHER_COLOR}'>${TEXT}</span>"

The answer printed inside the terminal is as expected (e.g.):<span color='#FFFFFF'>text and things</span>

And this should be good for i3blocks, but it doesn't work and i3blocks gives no errors.Though, if I manually insert WEATHER_COLOR="#FFFFFF" then i3blocks works.

So basically if the string is inserted manually, thus by writing $val="hexadecimal_value" it works, otherwise if it takes the output from the Python noscript it doesn't.

What could it be?

https://redd.it/yrs829
@r_bash
Recommended solution for determining if updates are available in rhel 8

I'm working on an ansible playbook and need a way to determine if they're updates available before doing the update step. Unfortunately, i haven't found a way with the ansible yum module. Additionally, I've been messing around with 'yum check-updates' command but the results aren't 100%. Is there a way to write a boolean expression to definitively determine if any updates are available?

https://redd.it/yrwuca
@r_bash
Local Variable escaping Function when it shouldn't

So I am stumped...

I am creating a couple Utility Functions as patterns to be used in a different of projects.

The first function:

ignorecase () { echo $1 | tr ':upper:' ':lower:' }

Makes any input used in it's argument, lower case. Works like a dream. Dead simple.

The second function which is depents on the first function:

SetVariableQ () {
unset "$1"; retries=0; maxretries=3
while [ $retries -lt $max
retries ]
do
clear; echo "Valid Options, yes/no: You have 3 Attempts"
retries=0
while read; do
remainattempts=$((("$maxretries") - 1 - ("$retries")))
case "$(ignorecase "
$REPLY")" in
y|yes ) answer=y; break;;
n|no ) answer=n; break;;
* ) if [ "$remainattempts" != "0" ] && ([ "$answer" != "y" ] || [ "$answer" != "n" ]); then
clear; echo "Valid Options, yes/no: "$remainattempts" Attempts Remaining."; fi
if [[ "$remainattempts" == "0" ]]; then answer=n; fi
echo "'
$REPLY' is an Invalid Option." >&2
if [ $((++retries)) -ge $max
retries ]; then
clear; echo "'"$1"' Variable has defaulted to 'no' due to Invalid Options Select."; break 2; fi;;
esac
done
if [ "$answer" == "y" ] || [ "$answer" == "n" ]; then break; fi
declare -g "$1"="$answer"; sleep .5; clear
done
}

Is meant to take any variable given as an argument, and then asks the user if they want that variable to be set to yes or no, then set that variable outside of the function to the users given answer.

The issue I am facing, is that the variable $answer that is used locally in this function to set the external variable, escapes the function. And I am at a loss as to why.

Can someone please help by explain where I have messed up?

Or even better, give a tip on a solution?

https://redd.it/ys1lbo
@r_bash
ltranslate: libretranslate in the terminal

Hi all! Earlier this morning I saw a post from u/Neon533 regarding his bash noscript, translate, which utilizes the Google Translate API. I thought to myself, "self, isn't there a LibreTranslate API?" And yes, yes there is.

So I wrote up an extremely similar simple bash noscript called ltranslate. It uses the German mirror of LibreTranslate. It doesn't have as many supported languages, but if you're looking for a non-Google alternative to Bash-translate, here it is.

Thanks go out to u/Neon533 for the inspiration. I know translate was a small simple noscript, but it was enough to inspire me to write this Libre version of it.

Codeberg

Github

https://redd.it/ys27f0
@r_bash
Could someone tell me why one of these works flawlessly, and the other is a buggy mess?

So, I'm going to show you two functions that are identical, save for how they get their data; one uses set variables, the other gets passed positional args. One works beautifully, the other is a buggy mess. Can anyone tell me why, though? I'm getting back into bash noscripting after a very long time (last time I noscripted bash before recently, redhat still had a consumer distribution), and this baffles me, because, to my mind, there's no real difference between the two, except for how the data is delivered to the function.

# Fonts
srcdir=".local/share/fonts"
destdir="fonts"
exportdata

export
data() {
if ! -d $userStore/$destdir ; then
echo "Creating $userStore/$destdir"
if ! mkdir $userStore/$destdir ; then
echo "Unknown error while creating directory '$userStore/$destdir'." >&2
exit 1
fi
fi

if ! -d /home/$user/$srcdir ; then
echo "$srcdir not found. Skipping."
else
echo "Exporting $srcdir"
while true; do echo -n .; sleep 0.2; done &
trap 'kill $!' SIGTERM SIGKILL # <-- I know this doesn't work :)

if ! cp -r /home/$user/$srcdir/ $userStore/$destdir ; then
echo "Unknown error while copying file(s) from /home/$user/$srcdir to $userStore/$destdir." >&2
exit 1
fi
echo 'done'
kill $!
fi
}


# Fonts
export_data ".local/share/fonts" "fonts"

export_data() {
if [ ! -d $userStore/$2 ]; then
echo "Creating $userStore/$2"
if ! mkdir $userStore/$2 ; then
echo "Unknown error while creating directory '$userStore/$2'." >&2
exit 1
fi
fi

if [ ! -d /home/$user/$1 ]; then # <-- This part in particular doesn't work in this version
echo "$1 not found. Skipping."
else
echo "Exporting $1"
while true; do echo -n .; sleep 0.2; done &
trap 'kill $!' SIGTERM SIGKILL # <-- I know this doesn't work :)

if ! cp -r /home/$user/$1/
$userStore/$2 ; then # <-- It just tries to copy the directory that doesn't exist like the conditional wasn't even there
echo "Unknown error while copying file(s) from /home/$user/$1 to $userStore/$2." >&2
exit 1
fi
echo 'done'
kill $!
fi
}

https://redd.it/ys2elr
@r_bash
How can I get the date of latest update pf their content for a list of directories from a txt file

Hi everyone,
I listed the content of a HD with the command
du -h --max-depth=3

Now, I have the list of the directories and the size of their content in a txt file.

I need to know for each directory how to get the date of the latest update (modif, addition... of a file) inside each of the directories.

I guess a loop
For d in file.txt
Do
Next

will be necessay, but how to get the information about the date?

Important informqtion (maybe): some of these subdirectories have a complex tree structure.

Can anyone help me with it?
I have been searching on the net and on furums... nothing nearing my request...

Thanks in advance

Edited: text layout

https://redd.it/ys7ied
@r_bash
Duplicate files with the same context

Hi,

I need to use single command to create the same 20 files that all of them contain the same sentence in linux, i tried a couple of commands but non of them seem to do exactly that.

Help anyone ?

https://redd.it/ys918y
@r_bash
Syntax error near unexpected token 'fi'

#! /bin/bash

drawLine(){
x1=$1
y1=$2
x2=$3
y2=$4

dx=$(($x2-$x1))
dy=$(($y2-$y1))
dx1=$dx
dy1=$dy

if $dx -lt 0
then
dx1=(-$dx)
fi
if $dy -lt 0
then
dy1=(-$dy)
fi
twody1=(2$dy1)
twodx1=(2
$dx1)
twody1minusdx1=$(($twody1- $dx1))
twodx1minusdy1=$(($twodx1- $dy1))

if [ $dy1 -le $dx1 ]
then
if $dx -ge 0
then
x=$x1
y=$y1
xe=$x2
else
x=$x2
y=$y2
xe=$x1
fi
echo $x
echo $y
for ((i=0; x -lt $xe; i++))
do
x=($x+1)
if $px -lt 0
then
px=$(($px + $twody1))
else
if $dx -lt 0 && $dy -lt 0
then
y=($y+1)
elif $dx -gt 0 && $dy -gt 0
then
y=($y+1)
else
y=($y-1)
fi
dy1minusdx1=$(($dy1-$dx1))
twody1minusdx1=(2*$dy1minusdx1)
px=$(($px + $two
dy1minusdx1))
fi
echo $x
echo $y
done

fi #(error line)


else
if $dy -ge 0
then
x=$x1
y=$y1
ye=$y2
else
x=$x2
y=$y2
ye=$y1
fi
echo $x
echo $y
for ((i=0; y<$ye;i++))
do
y=($y+1)
if $py <= 0
then
py=$(($py + $twodx1))
else
if $dx -lt 0 && $dy -lt 0
then
x=($x+1)
elif $dx -gt 0 && $dy -gt 0
then
x=($x+1)
else
x=($x-1)
fi
dx1minusdy1=$(($dx1-$dy1))
twodx1minusdy1=(2*$dx1minusdy1)
py=$(($py + $two
dx1minusdy1))
fi
echo $x
echo $y
done
fi
}


drawLine 0 1 2 3

This code gives error at line 65 and i dont know why.
I am trying to make a line drawing algo for bash terminal.

and i am stuck here

please help

https://redd.it/ysggci
@r_bash