r_bash – Telegram
Wrote a little noscript to translate any text from a terminal

Wrote a bash noscript for myself, and wanted to share with you.

You can translate a text on the go, in your terminal on Google supported languages
https://github.com/mariodujic/Bash-Translate

https://redd.it/ynni09
@r_bash
variable in while not working as expected

hi im noob bash user \^_\^ and i have problem with my noscript

#!/bin/bash -e
RETURNARRAY=( )

findarray () {
unset RETURNARRAY
RETURNARRAY=()
i=0
find "$@" | while read FINDLINE
do
echo i $i
RETURNARRAY[$((i++))]="
$FINDLINE"
echo ra* ${RETURNARRAY[*]}
echo ra0 ${RETURNARRAY[0]}
done
echo i-func $i
echo ra0-func ${RETURNARRAY[0]}
echo ra*-func ${RETURNARRAY[*]}
}

find . -type f -name "*.zip" -exec basename {} \; | while read FILE
do
NAME=$(echo
$FILE | cut -d \( -f 1)
EXTRA=${FILE:${
#NAME}}
find
array . -name "${NAME}\("
echo "ra0-main ${RETURNARRAY[0]}"
echo "ra
-main ${RETURNARRAY*}"
if $(find . -name "$NAME\(*" | wc -l) -gt 1 ;
then
echo $FILE
fi
done

my problem is that RETURNSARRAY is always empty

ok not allways echos for ra0 ra works as expected but ra0-func ra\-func ra0-main ra*-main are allways empty

i-func is also 0

can you help me?

https://redd.it/ynslna
@r_bash
How to shorten repetitive parts of a noscript?

I have had this in mind for a while now, but with no clue whatsoever if it's possible or not. Hope you guys can help me finally realize if it makes no sense or if it's something that can be done.

I have [this](https://github.com/rizzini/DotfilesGentooHome/blob/master/Documentos/noscripts/taskbar_disk_monitor.sh) noscript to print my storage devices' I/O stats. Basically, the noscript gets the stats of `/dev/sda`, `/dev/sdb` if exists, and `/dev/sdc` if exists, and, for each block device, it does the **exact** same if/else conditions for each. I have the feeling that the whole noscript could be a lot shorter.

Example:

if [ $((counter_no_data_sda+show_data_seconds)) == $counter_sda ]; then
do stuff;
fi
if [ $((counter_no_data_sdb+show_data_seconds)) == $counter_sdb ]; then
do stuff;
fi
if [ $((counter_no_data_sdc+show_data_seconds)) == $counter_sdc ]; then
do stuff;
fi

* As you guys can see, the only thing that changes is the name of the block devices, `sda`, `sdb`, and `sdc`.

**My question is**, is it possible to shorten these conditions to have one instead of three?

I'm thinking something like the example below. It's just an abstract idea, not real code:

if [ $((counter_no_data_sd{a,b,c}+show_data_seconds)) == $counter_sd{a,b,c} ]; then
do stuff;
fi

https://redd.it/yny9gh
@r_bash
Git batch mode?

I has been recently struggling to figure out a way to use git with bash noscripts(cronjobs), I don't know if there is something like a git batch mode, where I can read variables and text from a file when prompt to enter git credentials such like user email and token, sorry for the nook question, but could I have sources for studying how to use git with cronjobs?
The idea behind this tiny noscript is to keep a notations and general information repo always up to date.

https://redd.it/yoasq7
@r_bash
Tar archive

I have files.txt that contains list of files that I want to add to archive.tar.gz

# files.txt:
file1.txt
file2.txt
file3.txt

here is my command:

tar -cvf archive.tar.gz cat files.txt

It creates an empty archive. What do I do wrong?

https://redd.it/yog6mi
@r_bash
Dialog Backnoscript Problems

Hello, I am using dialog for a little noscript:

    #!/bin/sh
version="1.0"
DIALOG="dialog --colors --backnoscript "MyScript v$version""
$DIALOG --msgbox "Hello World\!" 0 0


this obviously doesn't work... so how to do this?

https://redd.it/yohxu2
@r_bash
Bash Scripts for OS dev

Hello r/bash, I recently been playing with various tutorials on https://wiki.osdev.org (which by the way has great resources for beginners and intermediate level learners. So I decided to create a GitHub repository that will hosts multiple noscripts (building a cross-compiler, and tutorial sections that will save a lot of time for users). please take a look at it and feel free to contribute to it.

Thanks a lot.

Here is the link to the repo: https://github.com/ByteSudoer/OS-Dev

https://redd.it/yohh2f
@r_bash
How to print both Decimal & Hexadecimal in a nice format?

To convert Decimal to Hexadecimal, printf can be used as follows:

$ printf '%X\n' 10
A
$

To print series of Decimal number to Hexadecimal:

$ printf '%X ' {8..17}; echo
8 9 A B C D E F 10 11
$

If you notice the alignment of Decimal & Hexadecimal are a little bit off

$ echo {8..17}; printf '%X ' {8..17}; echo
8 9 10 11 12 13 14 15 16 17
8 9 A B C D E F 10 11

What I would like to have is both formats in a nice format as follows:

$ convertDecimaltoHexadecimalCommand???
8 9 10 11 12 13 14 15 16 17
8 9 A B C D E F 10 11

What is the right way to do this? Thanks

https://redd.it/yom4j1
@r_bash
Want to check if an argument exists in a list

HIM=$1

TASKS=(
make_coffee
code
debug
)



Like in python3, is a for loop required with bash using a list to find element?

or can I just look for $HIM ==$TASKS

for task in "${TASKS[@]};
if [ $HIM == $task ]; then
echo "it is valid"
else
echo "it is not valid"

https://redd.it/yovr9s
@r_bash
align output

# (Beginner here) I try to align my output, is there a simple way to do it?

My noscript:

#!/usr/bin/bash
updated=": Is up to date"
notupdated=": Is not up to date; updating..."
cd
$HOME/.builds
for i in $(ls)
do cd $i
if [[ $(git pull) == "Already up to date." ]]
then
printf "$i$updated\n"
else
printf "$i$not
updated\n"
makepkg -sir > /dev/null
fi
cd ..
done

My output:

aic94xx-firmware: Is up to date
clipman: Is up to date
libfprint-tod-git: Is up to date
minesweeper-terminal-git: Is up to date
mkinitcpio-firmware: Is up to date
upd72020x-fw: Is up to date
wd719x-firmware: Is up to date
wev: Is up to date

The output I want:

aic94xx-firmware: Is up to date
clipman: Is up to date
libfprint-tod-git: Is up to date
minesweeper-terminal-git: Is up to date
mkinitcpio-firmware: Is up to date
upd72020x-fw: Is up to date
wd719x-firmware: Is up to date
wev: Is up to date

https://redd.it/youlr8
@r_bash
Some noscripts that might be useful

I recently decided to put my noscripts on GitHub. I figured it was a waste just keeping them to myself, if they can be useful to other people. So, here's hoping that they will be useful to others out there.

​

Linking some of the noscripts below, but there's more in that repository, and I will likely keep putting up more as I get to cleaning up my old noscripts.

​

https://github.com/linux4ever07/noscripts/blob/main/md5db\_fast.pl

An extremely fast (multi-threaded) Perl noscript to recursively keep track of changes in a directory.

​

https://github.com/linux4ever07/noscripts/blob/main/lower\_volume\_pw.sh

A noscript for the insomniacs out there who, like me, like to doze off to movies, YouTube etc. The noscript automatically and gradually lowers the volume to 0% over 1 hours time.

​

https://github.com/linux4ever07/noscripts/blob/main/tracker\_list.sh

A noscript that sorts through lists of BitTorrent trackers, removes duplicates and checks online status.

​

https://github.com/linux4ever07/noscripts/blob/main/bluray\_remux2hevc.sh

A noscript for the aspiring pirate who wishes to start a HEVC movie release group.

​

https://github.com/linux4ever07/noscripts/blob/main/imdb.sh

A noscript to search movies on IMDb from the terminal, and display basic info about the movie.

​

https://github.com/linux4ever07/noscripts/blob/main/round\_srt.sh

A noscript to round the start and stop timestamps in SRT subnoscript files to the closest centisecond. Makes it easier to edit timings in subnoscript editors such as Gnome Subnoscripts afterwards.

​

https://github.com/linux4ever07/noscripts/blob/main/free\_ram.sh

A noscript for those who have very little RAM. It frees up RAM by closing the rendering process of Firefox, Chrome / Chromium and Tor Browser, while leaving the tabs open so they can be reloaded if the user so wishes.

​

https://github.com/linux4ever07/noscripts/blob/main/packer.sh

An easy to use noscript which abstracts away the syntax differences between different compression programs.

​

https://github.com/linux4ever07/noscripts/blob/main/rm\_old\_kernels.sh

A noscript that automatically uninstalls old kernel packages from Fedora. Could be modified for other distros with little effort.

​

https://github.com/linux4ever07/noscripts/blob/main/cuebin\_extract.sh

A noscript to extract audio tracks from BIN/CUE files, and encode them to FLAC or Ogg Vorbis.

https://redd.it/yp8afm
@r_bash
Variable number of arguments?

Hello! I have a very simple question.

​

As a basic example, let's say you want to make a noscript that takes in an unlimited number of arguments and calculates the sum of the numbers passed in.

​

Example:

​

Running noscript: ./addNumbers.sh 1 2 3 4

Output: 10

​

Running noscript: ./addNumbers.sh 1 2 3 4 5

Output: 16

​

Is it possible to take input in this way and perform logic on each value passed in? How would you go about doing this?

https://redd.it/yp81bx
@r_bash
Is it possible to get strace to append to a file immediately?

Does anyone know how to get strace to append to a file immediately as stderr would, while using the -o option? So one can trace syscalls as they happen?

#!/bin/bash

background() {

cat "$1" | cut -f 2 -d$'\"' | grep "\S" | while read -r file; do
printf "$file " && date
done

}

trace_opens() {

local temp_pipe
temp_pipe="/tmp/tracer_pipe"
[[ ! -p "$temp_pipe" ]] || rm -rf "$temp_pipe"
mkfifo "$temp_pipe"
background "$temp_pipe" &
background_pid="$!"

stdbuf -i0 -o0 -e0 strace -A -o "| cat >>$temp_pipe" -f -e open,openat -y -- "$@"

wait "$background_pid"
}

trace_opens "$@"


https://redd.it/ypa03g
@r_bash
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