r_bash – Telegram
How do I go about mkdir with 3 different variables as a name of the directory?

How to mkdir with 2 different variables_$(date +%m-%d)

A=shopping

B=food

BOK=/Users/rpi/expense/book/$A_$B_$(date +"%m-%d")

mkdir -v -p "$BOK"

​

Only creates a directory with date. Any help would be appreciated.

https://redd.it/yniu94
@r_bash
proper syntax in bash, running out of quotes/delimiting?

newbie mistake but how do I format this correctly:

#!/bin/bash

echo 'this noscript has been invoked by "$USER" ';
echo 'the default gateway is: "route | grep default | awk '{print $2}'

I've tried a bunch of stuff but surely I'm missing something.

Ideally I want to print out only the 1st column, 2rd row of:

default 192.***.**.** 0.0.0.0 UG 100 0 0 eth0

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