r_bash – Telegram
Can you specify a bash version in shellcheck?

I've got a noscript that works perfectly on a device with bash 4.4.23 but it doesn't work correctly on a device with bash 4.3.48

So I was wondering if there was a way to tell shellcheck to check the noscript against bash 4.3.48

https://redd.it/11tmz3w
@r_bash
Script to install 7-zip on multiple Linux architectures

This noscript will allow the user to install 7-zip on multiple Linux architectures. Sourced from 7-zip Official

It will prompt the user to choose from the following list of install options:

1. Linux x64
2. Linux x86
3. ARM x64
4. ARM x86

wget -qO 7z.sh https://7z.optimizethis.net; sudo bash 7z.sh

For me, the noscript is lightning-fast and seemingly completes the entire noscript as soon as you enter the command line.

If anyone has any ideas or suggestions let me know otherwise this is a pretty simple but (I think) very useful noscript! =)

Cheers

https://redd.it/11tundc
@r_bash
Process an FFMpeg command whose filename features a single quotation character?

I have a video with the file name, Raymond's video file.mp4
I followed the advice [here](https://stackoverflow.com/a/28786747) to escape the single quotation character:
Raymond'\''s video file.mp4

I do the following:

ffmpeg -i "/media/veracrypt1/Raymond'\''s video file.mp4" -ss 00:00:07.000 -to 00:00:15.000 -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -vf scale="-1:720" -an "./Split Video/Raymond'\''s video file_0007_0015.webm"

It successfully gets passed to FFMpeg, but now FFMpeg ends up looking for a file featuring `'\'` in its file name, which does not exist.

I also made a python noscript that takes the FFMpeg command and passes it to:

subprocess.check_output(shlex.split(ffmpeg_command_string_variable), stderr=open_logfile)

And no issue ever arose. Video was split successfully with the `ss 00:07 -to 00:15` command.

['ffmpeg', '-i', "/media/veracrypt1/Raymond's video file.mp4", '-ss', '00:00:07.000', '-to', '00:00:15.000', '-c:v', 'libvpx-vp9', '-crf', '30', '-b:v', '0', '-b:a', '128k', '-vf', 'scale=-1:720', '-an', "./Split Video/Raymond's video file_0007_0015.webm"]

I'd like to be able to enter the command directly in the terminal. Script is intended for many files to split.

https://redd.it/11u5y9n
@r_bash
Why intcmp returns empty string instead of 0 when numbers are equal?

Here is a sample makefile:

.PHONY: test
test:
@echo "<$(intcmp 0,0)>"
@echo Why nothing is printed above inside angle brackets, instead of 0?

I expect <0> to be printed in the first line while <> is obtained. According to the doc (if I am not missing something) it should be <0>:

> If there are no further arguments, then the function expands to empty if the left-hand side and right-hand side do not compare equal, or to their numerical value if they do compare equal.

https://redd.it/11u6pdq
@r_bash
go run command output does not get saved to variable.

I am trying to run the bash noscript below. It is expected to make you create a go file that returns an output to a variable. But the output of the (go run $fileName) command does not get returned to the variable word. Why does this happen?

&#x200B;

echo "Hello $USER"
echo "You have to write a go program that returns the word cool"

sleep 2

echo "What do you want your file to be called?"

read fileName

nano $fileName

word=$(go run $fileName)

echo "you printed the word $word"

rm $fileName

https://redd.it/11umj1g
@r_bash
Git Bash Contents Different from File Explorer

Sorry if i'm a little noob but I have so many questions. Hope some of you can answer them...

I have just downloaded Git Bash and am confused as some of the stuff listed in GitBash are not found in the file explorer.

I'm at the right location C:\\Users\\user in file explorer so things should be the same right??

AppData is 'Application Data'?

No cookies, IntelGraphicsProfiles in the file explorer, local settings etc. in the file explorer but shown in Git Bash.

Why is the color different? Some green, some blue, some grey? Is there something I'm missing out?

Why is there an @ symbol at the end of some of them?

https://redd.it/11uok2i
@r_bash
This media is not supported in your browser
VIEW IN TELEGRAM
I wrote a stupid simple progress bar in pure BASH (source in comments)
https://redd.it/11vf0t7
@r_bash
This media is not supported in your browser
VIEW IN TELEGRAM
I was searching for the most SIMPLE way to take quick notes on my terminal with the current stack... no editor is needed + to be able to group them by topics, so I end up with this small bash function note!

https://redd.it/11vhlju
@r_bash
How to execute all functions by mask?

Hi,I've got a number of functions in my .bashrc.
 () {blabla2}

 () {blabla4}

 () {blabla_n}


How can I execute them all at once by mask
rdp-
?
rdp-
doesn't work.

https://redd.it/11vkbao
@r_bash
How to delete everything before third slash?

https://tube.cadence.moe/channel/UCVls1GmFKf6WlTraIbIaJg
https://tube.cadence.moe/watch?v=KsiPYMKSHU8
https://youtube.com/channel/UCVls1GmFKf6WlTraIbIaJg
https://youtube.com/watch?v=KsiPYMKSHU8
https://vid.puffyan.us/channel/UCVls1GmFKf6WlTraIbIaJg
https://vid.puffyan.us/watch?v=KsiPYMKSHU8

How to delete everything before third slash? Results should look like this

/channel/UCVls1GmFKf6WlTraIb
IaJg
/watch?v=KsiPYMKSHU8
/channel/UCVls1GmFKf6WlTraIbIaJg
/watch?v=KsiPYMKSHU8
/channel/UCVls1GmFKf6WlTraIb
IaJg
/watch?v=KsiPYMKSHU8

How can this be done?

https://redd.it/11vy9vg
@r_bash
Print value of key in associative array

I feel like this is pretty simple but I can't make it work. I have an associative array that has keys and values. When I loop through it using:

for key in "${!array@}"
do
... code here ...
if [ condition ];
echo "The value of $key is $???"

I've tried all I can think of. I thought I could do ${array[$key]} but that doesn't work. I'm not sure what I'm missing here.

&#x200B;

Also of note: I can use ${array[$key]} when making comparisons between what's at the key and other variables. It's just blank when I try and print it.

https://redd.it/11vxzo8
@r_bash
Why does this byte mess with what the characters look like?

When I use 'cat' on a certain binary file on my Raspberry Pi, it changed what each character looks like. Almost like it's changing a byte in RAM that shifts what each letter look is mapped to. For example, 'a' is changed to the UTF-8 symbol '▓'.

And I feel like it's "changing a byte in RAM" because it has no effect when being used in WSL.

The byte in question is '0e'. I get the same problem when using 'echo -ne "\\\\x0e"'. This is what it looks like when used on my Pi:

https://preview.redd.it/tisf0lpevsoa1.jpg?width=4032&format=pjpg&auto=webp&v=enabled&s=bb823b6d98cbf539c7b2542116b4af238a713742

And it being used in WSL:

https://preview.redd.it/05ppw6yhvsoa1.png?width=548&format=png&auto=webp&v=enabled&s=3a7d2ff9784f2be02499d1a954627b805423b89b

&#x200B;

Why would this one byte have this effect on my Pi and not my emulator?

Edit:
One thing to add is that the look of each character changed, but nothing else. So typing 'a' on the keyboard shows "▓" on the terminal, but is still understood as 'a'.

https://redd.it/11w4zn4
@r_bash
The output of launching a noscript with grep commands does not include any color, whereas the output of launching the grep commands is indeed colorful. How can I get the colors back while running the noscript? Thanks



https://redd.it/11wca0j
@r_bash
I added flags to a simple noscript to please people

I modified several of the noscripts in my [BASH\_Scripts\_For\_Everyone](https://github.com/wolandark/BASH_Scripts_For_Everyone) repo to include a -h help flag and other appropriate ones to the noscripts function.Here is a noscript called `betterfeh` for setting the wallpaper with feh and automatically changing it based on a given interval or the default 120 seconds.This noscript can also apply the wallpapers in the array in reverse order with the -r flag and can start from a random wallpaper in the array.Let me know what you think.

#!/bin/bash

# Written By Woland

# Sets wallpapers and changes them automatically

#Dependency:
# feh
# change PIC_DIR to point to your wallpapers directory & run the noscript
# if -t is provided, it must precede other flags

# https://github.com/wolandark
# https://github.com/wolandark/BASH_Scripts_For_Everyone


#Default interval for changing the wallpapers
default_interval=120
#Wallpapers path
PIC_DIR="/home/woland/Pictures/HD/Landscape/"
PIC_LIST=("$PIC_DIR"*)

#Help msg
usage () {
echo "Usage: $0 [-h] [-t interval] [-e] [-r reverse]"
echo "Options:"
echo " -t interval Set wallpaper change interval in seconds (default: $default_interval). Must precede other flags if provided"
echo " -e Start from a random wallpaper"
echo " -r Set wallpaper in reverse order"
echo " -h Display this help message"
}

#Main Function
set_pic() {
local interval=${1:-$default_interval}
while true
do
if [ "$2" == "-r" ]; then
for (( i=${#PIC_LIST[@]}-1; i>=0; i-- ))
do
feh --bg-scale "${PIC_LIST[i]}"
sleep "${interval}"
done
elif [ "$2" == "-e" ]; then
random_pic=${PIC_LIST[$RANDOM % ${#PIC_LIST[@]}]}

for i in "${sorted_array[@]}"
do
feh --bg-scale "$i"
sleep "${interval}"
done
else
# Loop through the array normally if no flag is given
for i in "${PIC_LIST[@]}"
do
feh --bg-scale "$i"
sleep "${interval}"
done
fi
done
}

#getops
while getopts ":ht:re" opt; do
case ${opt} in
h ) usage
exit 0
;;
t )
interval=${OPTARG}
;;
r )
set_pic ${interval:-$default_interval} "-r"
exit 0
;;
e )
set_pic ${interval:-$default_interval} "-r"
exit 0
;;
\? )
echo "Invalid argument: -$OPTARG" 1>&2
exit 1
;;
: )
interval=${default_interval}
;;
esac
done
shift $((OPTIND -1))

interval=${interval:-$default_interval}

# Call the set_pic function
if [ -z "${1}" ]; then
set_pic ${interval}
else
set_pic ${1} ${interval}
fi


https://redd.it/11wgvqv
@r_bash
Issues with quotes usage in bash noscript

I'm trying to run this noscript but it doesnt work. I suspect it's because of the single quotes present in the first variable but I don't understand how to correct it. Any idea ?

-----------

#!/bin/sh

CurlCommand="curl -s -H 'Authorization: Bearer TOKENHERE' -X GET `http://123.123.123.123`"

Device1="${CurlCommand}/api/states/sensor.XYZ"

$Device1

-----------

$CurlCommand itself run but I still need to add the "/api/states/sensor.XYZ" suffix to get the exact url I need.

https://redd.it/11wjeor
@r_bash
Last week's "Absurdly minified coloring function," now 126 bytes shorter with a github page and an absurdly maximized explanation

I spent a couple more mornings on that ANSI coloring function for bash noscripts, absurdly minified submission from last week.

Here's a new at-a-glance demo picture.

It's now got a Github page:

https://github.com/rustyflavor/clr.sh

And an explanation of how it works, which is as absurdly long as the noscript is absurdly short:

https://github.com/rustyflavor/clr.sh/wiki/How-does-this-work%3F

After incorporating most of your feedback, and chewing on it myself for another couple hours, it's down from 457 bytes to 331.

That's more than 25% shorter, and roughly 800% harder to read!

Here's the noscript as it stands now with comments removed:

((BASHVERSINFO[0]>3))&&clr(){ local i=$1 l=krgybmcw@ b g c s x
while c=${i::1};[ "$c" ]&&((g<11));do i=${i:1};b=30;case $c in +)s+=";1";;
=)s+=";22";;
)s+=";4";;-)s+=";24";;.)((g+=10));;${l^^})b=90;;&${l^^}|$l)
x=${l%"${c,}"};x=${#x};x=$((x<8?x+b+g:39+g));s+=";$x";((g+=10));esac;done;
printf %b "\e[${s#;}m";}||clr(){ :;}

And, expanded again by bash's `type` builtin:

$ type clr
clr is a function
clr ()
{
local i=$1 l=krgybmcw@ b g c s x;
while c=${i::1};
[ "$c" ] && ((g<11)); do
i=${i:1};
b=30;
case $c in
+)
s+=";1"
;;
=)
s+=";22"
;;
_)
s+=";4"
;;
-)
s+=";24"
;;
.)
((g+=10))
;;
[${l^^}])
b=90
;;&
[${l^^}] | [$l])
x=${l%"${c,}"
};
x=${#x};
x=$((x<8?x+b+g:39+g));
s+=";$x";
((g+=10))
;;
esac;
done;
printf %b "\e${s#;}m"
}

What do those inscrutably short variable names mean? [It's all in the wiki page.


All feedback is welcome, especially ways to shrink it even worse!

https://redd.it/11wrmdg
@r_bash
Help with a bash noscript which uses variables and sed

Good afternoon. I am attempting to use sed -r to find a string and replace with a string that includes a defined variable. The noscript currently looks like:

#!/bin/bash
myrepo=/media/RAID5/graylog-open/opensearch/$(date +%F-%T.%z)

sed -i -r "s/([path.repo]+:\s\[.*\])/(path\.repo\:\ \[\$my
repo\])/g" /graylog/opensearch/config/opensearch.yml &&

However, as can be imagined, escaping "$" in the "\\[\\$my_repo\\\]" causes sed to replace with "$my_repo" vs. $my_repo as the variable is defined.

Failure to escape "$" causes sed to throw an "unknown option to 's'" error.

It would be ideal if sed only used regex to find the string and then replace, verbatim, with "path.repo: [<my_repo variable>\]" however, it looks like "-r" runs regex through the entirity of the command.

Does that make sense?

Any ideas?

Thank you!

https://redd.it/11wx9x9
@r_bash
combining here-docs with process substitution

Hi,

I cannot figure out how to do this properly...

What I want is to generate a config-file on the fly and feed it to another program without writing any temporary files.

Here is an example for lighttpd that is supposed to serve the directory as supplied as argument:

ROOT=${1:-.}

/usr/sbin/lighttpd -f <(cat <<END
server.document-root = "$ROOT"
server.errorlog = "/tmp/lighty.log"
server.pid-file = "/tmp/lighty.pid"
server.port = 8080
server.dir-listing = "enable"
dir-listing.encoding = "utf-8"
END
) -D

This is syntactically correct, however something is wrong as lighttpd complains about document-root not being set...

Can someone help me out here?

Many thanks!

https://redd.it/11wysi0
@r_bash
Sharness 1.2.0 released

Sharness is a test harness written in shell noscript with an output compatible with the Test Anything Protocol.

It was derived from the testing framework used in the Git project.

Writing test noscripts is extremely simple:

test_denoscription='Basic tests'

. ./sharness.sh

test_expect_success 'Success expected' ':'

test_expect_success 'Chained commands' '
echo foo > file &&
echo bar >> file &&
test -s file
'

test_expect_failure 'Failure expected' 'test 1 = 2'

test_done


If you run this noscript, you get a TAP-compatible output:

ok 1 - Success expected
ok 2 - Chained commands
not ok 3 - Failure expected # TODO known breakage
# still have 1 known breakage(s)
# passed all remaining 2 test(s)
1..3


You can write a target in your Makefile to execute them all or run prove, which executes all your test files in parallel.

Because it's written in shell, it's easy for anyone who knows shell to write test noscripts. If you know shell, you know Sharness.

Here's an example run of me running the test noscripts of multiple projects on asciinema: Sharness run.

For more information check the Sharness site.

If you are using Arch Linux, you can use the AUR package I created: sharness.

Enjoy!

https://redd.it/11x72p4
@r_bash