r_bash – Telegram
can you explain what this does?

echo '[q]sa[ln0=aln256%Pln256/snlbx]sb5567320342535949633984860024054390510049758475925810612727383477870370412074937779308150930912981042snlbxq'|dc



(It is in a single line)

https://redd.it/1ighyqf
@r_bash
I need your help

Hello, I am quite new on Linux and I wanted to make a bash noscript that has my Linux desktop environment, customisation, apps etc at once because I switch computers quite often and don't want the hassle of doing these every time I switch devices. If it's possible a yt video would be very helpful but I appreciate all the answers. Thank you!

https://redd.it/1ifj9me
@r_bash
nesting command substitutions

My goal is to use dmenu to browse a small set of applications. A list of such applications is in \~/prj/dmenus/favorites/a.txt. If I invoke $(cat ~/prj/dmenus/favorites/a.txt | dmenu)

I get just what I'm after. If I invoke

$(cat ~/prj/dmenus/favorites/a.txt | dmenu -fn 'Droid Sans Mono-18')

I get a output that is nicer to read. Next step, I would like to put the formatting options in a file. I can access that file and read it into a variable by another command substitution.

Example:x=$(<~/.config/dmenu/layout.txt); echo $x yields -fn 'Droid Sans Mono-18'

That is as far as I get. Can't seem to execute in the out command substitution.

$(cat ~/prj/dmenus/favorites/a.txt | dmenu $x)

usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]

[-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]

Not what I want Similarly, if I use

$(cat ~/prj/dmenus/favorites/a.txt | dmenu $(<~/.config/dmenu/layout.txt))

usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]

[-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]

Same failure. I bet the solution is really simple, and will enlighten me immensely.

I am using ubuntu 24.04 with fluxbox.

Thanks

Ti











https://redd.it/1ih44b2
@r_bash
Is there a way to get History without <enter>?

Hi, I'd like to get a past command of history for example !1900 but without enter, so I can rewrite that command for this instance and then manually I will do then <enter> for this new changed command?

Regards!

https://redd.it/1ih5bpo
@r_bash
Sed/awk help

Hi, I have text files that contain lists of numbers. Each number is on a separate line. Some of the numbers have forward slashes in the middle (eg 11152/3), some of them don't (eg 11276), which is fine.

However due to the way I collected the data, there are some lines that just have an assortment of slashes and spaces on them and nothing else.

Is there any way I can use sed or awk to get rid of the unwanted slashes whilst keeping the wanted ones?

https://redd.it/1ihd4yv
@r_bash
looking for a way to have a yes or no option at the end of a noscript to start another noscript or exit.

I have a simple backup noscript that creates archives of data. At the end of the noscript it encrypts and then uploads to a cloud server.

I'd like to make this into two noscripts with an option at the end of the first to run the second noscript or exit. i.e, I don't always want to encrypt and upload.

Any ideas?

https://redd.it/1ihisxo
@r_bash
Window Tiling Script w/ xdotool and wmctrl not persistent after switch workspaces

So I'm running xfce4 as my DE (w/ xfwm4 as the WM) and the window tiling that comes default is awesome \*if\* you're using a monitor(s) with normal dimensions. I got a nice ultrawide monitor a while back and the tiling, while still effective, doesn't quite tile the way it would on a standard monitor. I've been meaning to write a noscript to tile more effectively on an ultrawide monitor for a while now and I **finally got around to it** about a week ago.

Things are going great and it works exactly as expected (sort of). I pasted the code below (but I must warn you I'm still pretty new to bash noscripting so there might be an simpler way to accomplish the same thing). I basically find what window is active with xdotool, figure out what monitor that window is on (with some wizardry I found on StackExchange), and tile the window with wmctrl based on the argument passed to the noscript. Then I just programmed each of the variations with different arguments to different keyboard shortcuts and \*chef's kiss\*

**Here's the problem:** every time I change workspaces and change back, one or more of the windows I've tiled with my noscript move around to a different position and size. Is there any reason this could be happening with my noscript or could it be something else in the window manager overriding things?



`# This noscript is meant to tile windows into smaller regions`

`# than what is available by default in xfce4.`

`#`

`# Ultra-wide monitors are effective as a seamless dual monitor,`

`# but window tiling acts different. This is a fix for that issue.`

`# Don't bother using this noscript on a standard monitor. It will`

`# work, but the windows will be unusable.`

`#`

`# This noscript will separate the monitor into 8 regions, 4 on`

`# the top half of the screen and 4 on the bottom, with each`

`# given a letter signifier representing a physical mapping of`

`# a keyboard, like so:`

`#`

`# -----------------`

`# | Q | W | E | R |`

`# |---------------|`

`# | A | S | D | F |`

`# -----------------`

`#`

`# Additionally, there will be 4 more regions with 100% height,`

`# from left to right:`

`#`

`# -----------------`

`# | | | | |`

`# | H | J | K | L |`

`# | | | | |`

`# -----------------`

`#`

`# This gives a total of 12 tiling variations available that`

`# mimic default tiling on a standard monitor. Simply pass`

`# the letter designation of the region you wish to tile your`

`# focused window to as the only argument.`

`#`

`# For example:`

`# 'window-tile.sh -Q' tiles the active window to the top-left`

`# region.`

`#`

`# Each variation can be tied to keyboard shortcuts for easy tiling.`

`# I used <ctrl>+<super>+<letter>`







`# Get active window as decimal using xdotool`

`FOCUSED=$(xdotool getactivewindow)`



`# Convert decimal value to hex for use with wmctrl`

`FOCUSED=$( echo "obase=16; $FOCUSED" | bc )`

`FOCUSED=$( echo "0x0$FOCUSED" | awk '{print tolower($0)}' )`



`# Thanks to terdon from the PowerUser StackExchange for this`

`# next section to determine the current monitor.`



`## Get screen info`

`screen1=($(xrandr | grep -w connected | awk -F'[ +]' '{print $1,$3,$4}' |`

`head -n 1))`

`screen2=($(xrandr | grep -w connected | awk -F'[ +]' '{print $1,$3,$4}' |`

`tail -n 1))`



`## Figure out which screen is to the right of which`

`if [ ${screen1[2]} -eq 0 ]`

`then`

`right=(${screen2[@]});`

`left=(${screen1[@]});`

`else`

`right=(${screen1[@]});`

`left=(${screen2[@]});`



`fi`



`## Get window position`

`pos=$(xwininfo -id $(xdotool getactivewindow) | grep "Absolute upper-left X" |`

`awk '{print $NF}')`



`## Which screen is this window displayed in? If $pos`

`## is greater than the offset of the rightmost screen,`

`## then the window is on the right hand one`



`# Parse resolution of current monitor and assign to`

`# $WIDTH and $HEIGHT`

`if [ "$pos" -gt "${right[2]}" ]`

`then`

`# echo
"${right[0]} : ${right[1]}"`

`IFS=x read -r WIDTH HEIGHT <<< ${right[1]}`

`else`

`# echo "${left[0]} : ${left[1]}"`

`IFS=x read -r WIDTH HEIGHT <<< ${left[1]}`

`fi`



`# Tile the focused window based on argument passed.`

`# Position and size is determined by the resolution of the current moniter:`

`# if $HEIGHT=1440 and I want the window to equal half the height of the`

`# screen, I would use $(( $HEIGHT / 2 )). Enter 'man wmctrl' in your`

`# terminal prompt to get more information on the wmctrl command.`



`if [ $1 = '-Q' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,0,0,$(( $WIDTH / 4 )),$(((( $HEIGHT / 2 )) - 1))`

`elif [ $1 = '-W' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,$(( $WIDTH / 4 )),0,$(( $WIDTH / 4 )),$(((( $HEIGHT / 2 )) - 1))`

`elif [ $1 = '-E' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,$(( 2 * (( $WIDTH / 4 )))),0,$(( $WIDTH / 4 )),$(((( $HEIGHT / 2 )) - 1))`

`elif [ $1 = '-R' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,$(( 3 * (( $WIDTH / 4 )))),0,$(( $WIDTH / 4 )),$(((( $HEIGHT / 2 )) - 1 ))`

`elif [ $1 = '-A' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,0,$(( $HEIGHT / 2)),$(( $WIDTH / 4 )),$(( $HEIGHT / 2 ))`

`elif [ $1 = '-S' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,$(( $WIDTH / 4 )),$(( $HEIGHT / 2 )),$(( $WIDTH / 4 )),$(( $HEIGHT / 2 ))`

`elif [ $1 = '-D' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,$(( 2 * (( $WIDTH / 4 )))),$(( $HEIGHT / 2 )),$(( $WIDTH / 4 )),$(( $HEIGHT / 2 ))`

`elif [ $1 = '-F' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,$(( 3 * (( $WIDTH / 4 )))),$(( $HEIGHT / 2 )),$(( $WIDTH / 4 )),$(( $HEIGHT / 2 ))`

`elif [ $1 = '-H' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,0,0,$(( $WIDTH / 4 )),$(( $HEIGHT ))`

`elif [ $1 = '-J' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,$(( $WIDTH / 4 )),0,$(( $WIDTH / 4 )),$(( $HEIGHT ))`

`elif [ $1 = '-K' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,$(( 2 * (( $WIDTH / 4 )))),0,$(( $WIDTH / 4 )),$(( $HEIGHT ))`

`elif [ $1 = '-L' ]`

`then`

`wmctrl -ir $FOCUSED -e 0,$(( 3 * (( $WIDTH / 4 )))),0,$(( $WIDTH / 4 )),$(( $HEIGHT ))`

`else`

`echo "Argument required"`

`fi`



https://redd.it/1iirxja
@r_bash
help in named pipes

Hi everyone,

I have a question, I was studying a Linux privilege escalation course, and I came across a systemctl abuse https://gtfobins.github.io/gtfobins/systemctl/#sudo

and then I ask myself why not to do it but get interactive shell, using two named pipes, example:

f1=/tmp/infifo
f2=/tmp/outfifo
mkfifo $f1 $f2
sf=mktemp.service
echo -e "Service\nExecStart=eval \"/bin/bash < $f1 > $f2 &\"\nInstall\nWantedBy=multi-user.target" > $sf
sudo systemctl link $sf
sudo systemctl enable $sf --now
cat $f2 &
cat > $f1

but it did not work, but if I tried it without systemctl, am I using pipes incorrect?
and can you help me understanding named pipes and how to use it?

https://redd.it/1ij1agl
@r_bash
Authorized one way but unauthorized the other

When I run curl commands independently in iTerm2, I am able to get a file back that I need with no issue. However, when I run those same commands in a bash noscript, I get unauthorized. The tokens are the same both ways. I can give more info if needed, but why would this be happening?

https://redd.it/1ij5qpj
@r_bash
is anything like "rm all except this, this2, this3"

Hi, I should remove some files.jpg (from 20 +/-) except 3 of them

rm all except DSC1011.jpg Dsc1015.jpg Dsc1020.jpg

what will be the command?

and of course for your GIANT HELPING ALWAYS GENIUSES

https://redd.it/1ijda50
@r_bash
Depth first or breadth first after learning Linux terminal & Shell noscripting?


Few things on my mind but unsure if I am eligible to learn it..

- gitlab (Mastering gitlab 12)

- Elasticsearch(Not sure of the text to read)

- DNS & BIND (Pro DNS & BIND 10)

- DBA (Pro MySQL)


(Obviously looking into devops route)

https://redd.it/1ikkw26
@r_bash
line buffering vs block buffering

Hi, after trying appending to a file with awk some weird occurrence happened

awk -i inplace '{print $0} ENDFILE{print "endoffile"}' somefile

the next command in terminal finish immediately and throws an error with exit status 1:

cat -A
cat: -: input file is output file

Now the `grep` (which has `--line-buffered` as a possible flag) does fine

grep -

So, my suspicion was `awk -i inplace` has done something wrong, and the [inplace extension manual](
https://www.gnu.org/software/gawk/manual/htmlnode/Extension-Sample-Inplace.html) does suggest so

>redirect gawk's standard output to /dev/null

Slightly different from suggested, but this works

awk -i inplace '{print $0} ENDFILE{print "endoffile"}' somefile &>/dev/null

also `sed --in-place` has no problem at all

sed -i '$r /dev/stdin' some
file <<< "endoffile"

So what is the cause of this, and is the manual slightly wrong? It doesn't seems awk -i inplace is like sed -i emulation, like suggested. Also, is &>/dev/null mandatory to follow inplace extension?



https://redd.it/1ikudxt
@r_bash
Learning bash, trying to get it to do something stupid

I'm writing a noscript to handle my code projects, and something stupid I want to add is an ffmpeg command to play every mp3 in a folder after it opens my project in the IDE. Me & GPT (good idea for a romance novel, you're welcome) got this far:

for i in *.mp3; do

ffplay -nodisp -autoexit "/home/scottishcomedian/Music/bash_bullshit/$i"

done

And when I run it, it just hits me with the blank console. What am I doing wrong, oh wise elders?

https://redd.it/1invmde
@r_bash
illegal number problem

Hey, I struggle with some noscript.

var="nef892na9s1p9asn2aJs71nIsm"

for counter in {1..40}
do
var=$(echo $var | base64)
if $counter -eq 35
then
echo $var | WC -c
fi
done

It always give me: illegal number: {1..40}
Can someone help?

https://redd.it/1iogfzm
@r_bash
How to parse a nested JSON file in an old unix version

Hi, I'm trying to split a JSON file by transaction_id wherein 1 transaction_id=1 record. However, I feel like my shell noscript is failing due to the fact that it cannot read the JSON file and it won't proceed to processing on what I want it to do. You may see the snippet of my code below.


# Extract all transaction_id values using a regular expression

echo "$content" | sed -n 's/.*"transaction_id":\s*"\([^"]*\)".*/\1/p' | while read transaction_id; do

# Debugging: Show the current transaction_id being processed and log it

echo "Processing transaction_id: $transaction_id" | tee -a "$BATCH_LOG"



# Get the last character of the transaction_id

last_char="${transaction_id: -1}"



# Debugging: Show the last character of the transaction_id and log it

echo "Last character of '$transaction_id': $last_char" | tee -a "$BATCH_LOG"



# Check the last character and categorize

if [[ "$last_char" =~ [0-4] ]]; then

echo "$transaction_id" >> "${file%.json}_01.json"

# Debugging: Log which file the transaction_id is being saved to

echo "Saved to: ${file%.json}_01.json" | tee -a "$BATCH_LOG"

elif [[ "$last_char" =~ [5-9] ]]; then

echo "$transaction_id" >> "${file%.json}_02.json"

# Debugging: Log which file the transaction_id is being saved to

echo "Saved to: ${file%.json}_02.json" | tee -a "$BATCH_LOG"

elif [[ "$last_char" =~ [a-l] ]]; then

echo "$transaction_id" >> "${file%.json}_03.json"

# Debugging: Log which file the transaction_id is being saved to

echo "Saved to: ${file%.json}_03.json" | tee -a "$BATCH_LOG"

elif [[ "$last_char" =~ [m-z] ]]; then

echo "$transaction_id" >> "${file%.json}_04.json"

# Debugging: Log which file the transaction_id is being saved to

echo "Saved to: ${file%.json}_04.json" | tee -a "$BATCH_LOG"

else

# Debugging: Log unexpected last characters

echo "Unexpected last character '$last_char' for transaction_id: $transaction_id" | tee -a "$BATCH_LOG"

fi

done


I hope someone can help I've been losing my mind over this.

https://redd.it/1ip6rpi
@r_bash
Transposing args in noscript, including quotes

I'm trying to create a noscript to interact with my docker containers without having to shell in and run commands manually. It's a very simple noscript:

#!/bin/bash

ALLARGS="$@"
docker compose exec api ash -c "cd ../ && alembic ${ALL
ARGS}"

I tried a few things (${ALL_ARGS//\"/\\\"}, sed, others), but finally noticed that "$@" simply doesn't contain the double quotes. Is there a way to transpose the args as is?

https://redd.it/1iow04v
@r_bash
Check if number of arguments is one after all the flag

I have a noscript who can take more than one flag.

./noscript -a list is the same than ./noscript list all but list can have other parameter than all so what i want is ./noscript -a list somethingHere give a error.


So what i have test is if $3 is empty when -a is given.

But if the user type ./noscript -a -s list this give a error because $3 is no longer empty but the exeption behavior is to work.

if aflag = 1 and (after 'list' is empty)
do something
else
error

So my idea is this on pseudo code. But i don't know how to check dynamicly if the $n+1 after list ( $n) is empty

https://redd.it/1ip7zyv
@r_bash
Unexpected curl command behaviour ?

The following command reads the exchange rate information for the EUR/USD currency pair from HTML page and prints it.

page=$(curl -s https://www.widgets.investing.com/live-currency-cross-rates?theme=darkTheme&pairs=1); echo "$page" | pup 'div.pid-1-bid text{}'

But why doesn't the following command work, instead it prints the entire page?

curl -s https://www.widgets.investing.com/live-currency-cross-rates?theme=darkTheme&pairs=1 | pup 'div.pid-1-bid text{}'

https://redd.it/1imsp0s
@r_bash
WHAT IS BASH DOING?

**UPDATE**

So it looks like FFPMEG is interacting with the shell in some way... so adding this to the FFPMEG line seems to have resolved the issue.

</dev/null >/dev/null 2>&1



I am doing something dumb... I guess? But I can't figure out what in the heck, when using the EVAL statement, previous variables are stripping off a character for every other loop? Sound confusing? I am confused...

I am using FFMPEG and writing a quick little bash wrapper to automatically detect silences and split apart an audio file.

Let me see if I can show what is going on... This is WITHOUT the eval command...

IFS='\r\n'
while read -r line1; do
IFS= read -r line2
echo "Start: $line1"
echo "End: $line2"
echo "Prev: $PREV"
START="${PREV}"
END="${line1}"

echo "/usr/bin/ffmpeg -hidebanner -loglevel error -i ./${INPUT} -ss ${PREV} -to ${line1} output${COUNT}.wav"
COMMAND='/usr/bin/ffmpeg -hidebanner -loglevel error -i '
COMMAND+="./${INPUT} -ss ${START} -to ${END} output
${COUNT}.wav"

echo "${COMMAND}"
# eval ${COMMAND}

COUNT=$(( COUNT + 1 ))
PREV=$line2
echo ''

done <<< $SILENCES

This outputs exactly what I would expect...

Start: 6.04
End: 6.30
Prev: 0
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 0 -to 6.04 output0.wav
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 0 -to 6.04 output0.wav
Start: 21.72
End: 21.98
Prev: 6.30
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 6.30 -to 21.72 output1.wav
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 6.30 -to 21.72 output1.wav
Start: 24.18
End: 24.53
Prev: 21.98
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 21.98 -to 24.18 output2.wav
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 21.98 -to 24.18 output2.wav
Start: 43.34
End: 43.58
Prev: 24.53
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 24.53 -to 43.34 output3.wav
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 24.53 -to 43.34 output3.wav

SO then I uncomment the eval command. That is the only change. I have tried with and without " ", using and not using { } to see if I am interpretting the string differently.

`eval ${COMMAND}`

SOOOO.... Here is the output

Start: 6.04
End: 6.30
Prev: 0
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 0 -to 6.04 output0.wav
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 0 -to 6.04 output0.wav

Start: 1.72
End: 21.98
Prev: 6.30
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 6.30 -to 1.72 output1.wav
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 6.30 -to 1.72 output1.wav
-to value smaller than -ss; aborting.

Start: 24.18
End: 24.53
Prev: 21.98
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 21.98 -to 24.18 output2.wav
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 21.98 -to 24.18 output2.wav

Start: 3.34
End: 43.58
Prev: 24.53
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 24.53 -to 3.34 output3.wav
/usr/bin/ffmpeg -hidebanner -loglevel error -i ./audio.wav -ss 24.53 -to 3.34 output3.wav
-to value smaller than -ss; aborting.

SO Every other iteration... the ${PREV} variable has the first digit/character stripped. So for the second iteration:

21.72 -> 1.72

BUT this ONLY happens when I have the EVAL command AFTER the echo commands. So somehow the eval command is affecting that variable, but I can't see how. Thanks!

https://redd.it/1im9sik
@r_bash