r_bash – Telegram
Auto-generate folders and convert files!

Hello,

I am trying to create a bash noscript that converts h.265 to h.264 and I would like for it to loop through each folder, convert all mkv files and then in another folder create an identical folder with the converted mkv. Essentially if there's a show with many seasons I want it to loop through each season then store the converted file in another folder with the folder name being the season it came from and so on.

Btw I'm newbie :D

Here's what I'm currently doing:

for i in *.mkv;
do name=`echo "$i" | cut -d'.' -f1`
echo "$name"
ffmpeg -i "$i" -map 0 -c:v libx264 -crf 18 -c:a copy rest1/"${name}.mkv"
done

What I'm thinking about: (this is mainly pseudo code)

for i in */;
(creates a folder named the same)
do
for i in *.mkv;
do name=`echo "$i" | cut -d'.' -f1`
echo "$name"
ffmpeg -i "$i" -map 0 -c:v libx264 -crf 18 -c:a copy ${foldernamehere?}/"${name}.mkv"
done
done

Thank you!

https://redd.it/10fn1if
@r_bash
Replace IPTables Rule Based on Rule Specification

In a noscript I have the specification of an iptable rule (like what would be used with the "iptable -A" command) that already exists and I need to replace it. Unfortunately the "iptables -R" command expects a rule number not a rule specification. Is there a way to get the rule number of a rule based on its specification? Or is there some other approach to take to replace a rule if all you have is its specification in a noscript?

https://redd.it/10g7f9b
@r_bash
monthly crontab jobs

Any idea how i can get a crontab job to run on every 2nd Wednesday of each month? not sure i can get that scheduled using crontab

https://redd.it/10gddja
@r_bash
pls help with bluetoothctl wrapper noscript ("Missing dev argument")

Hi everybody,

I am trying to write a wrapper noscript for bluetoothctl to easily connect/disconnect particular devices.

I base it on this arch wiki entry. THIS is my noscript (pastebin link).

When I run bluetoothhandler.sh trennen az_lautsprecher, it will disconnect that device and show the expected output that bluetoothctl produces; however, when I run bluetoothhandler.sh verbinden az_lautsprecher, I just get Missing dev argument.

I don't understand this. The syntax is the same for connecting and disconnecting; the functions are constructed accordingly. Yet one works, the other does not.

When I manually run bluetoothctl -- connect AB:06:CD:49:EF:E3 in the terminal, it works fine as well. When the noscript runs it, it won't work at all, while disconnect does work either way (both in the noscript and in the terminal).

Can you please tell me what I need to change in order to make connect work as well? Thank you in advance for your help :)

https://redd.it/10grvms
@r_bash
mv: cannot stat?

inotifywait -m /home/aku/Downloads -e create -e moved_to |
while read directory action file; do
if [[ "$file" =~ .*png$ || "$file" =~ .*jpg$ || "$file" =~ .*gif$ || "$file" =~ .*webm$ ]]; then
sleep 4
echo "$file"
echo $(mv "$file" "/home/aku/Pictures/Downloads")
fi
done

I have this pretty simple shell noscript, which takes pictures that are saved to my downloads folder, then moves them to a different folder. Every time I try and test it, I get an error: cannot stat: no file or directory.

Any advice? I think the issue is with this line : echo $(mv "$file" "/home/aku/Pictures/Downloads"), as you can probably tell I've experimented with quite a few syntax and nothing has worked.

https://redd.it/10gul4c
@r_bash
Help needed with getting all the lines containing <noscript></noscript> for a simple rss noscript

So this is the basic noscript:

>\#!/bin/bash
\# URL of the RSS feed
FEED_URL=" http://rss.cnn.com/rss/cnn\_topstories.rss"
\# Download the RSS feed
curl -s $FEED_URL > feed.xml
\# Extract the article noscripts
grep -E "<noscript>[\^<\]+</noscript>" feed.xml | sed -e "s/<noscript>//" -e "s/<\\/noscript>//"

The problem is that it gets all the xml and the grep and sed commands aren't doing anything.

I also tried these patterns:

>grep -E "<noscript>[\^<\]+</noscript>" feed.xml | sed 's/<noscript>\\|<\\/noscript>//g'

and:

>grep -E "<noscript>[\^<\]+</noscript>" cnn_topstories.rss | sed -n -e "s/<noscript>//" -e "s/<\\/noscript>//p" | tr -d '\^[0-9\]\\{1,\\}[:blank:\]'

and even with awk:

>grep -E "<noscript>[\^<\]+</noscript>" cnn_topstories.rss | awk -F'<noscript>|</noscript>' '{print $2}'

but nothing seems to do what I want.

I just want to get the noscript tags from the xml and echo all of them in a new line.

is that too much to ask LoL?
Any help is much appreciated

https://redd.it/10gb6mq
@r_bash
How to increment an index refer to parameter to read the value?

First time doing any bash noscripting so having some difficulties with it being so low level


Given the noscript below, how do I increase the index in the second part of the echo statement so that it prints the next parameter value (i.e print the first parameter, then print the second parameter)

paramIndex=1

while [ $paramIndex -le $# ]

do

echo "${!paramIndex}" "${!paramIndex}"

((paramIndex++))

done

So, for example running is as 'sh mynoscript.sh param1 param2' should echo:

param1

param2

&#x200B;

Currently its just printing param1 twice, and I've tried everything I've found online, but just cant get it to work

https://redd.it/10h2tjy
@r_bash
Calculate sum of pattern occurence in text file

So I have a text file, with each line being "X tests passed". X can be any number. I want to loop through the whole file and add up all the numbers, so the output would be "N tests passed" where N is the sum of all tests passed. How do I do this?

https://redd.it/10h2i85
@r_bash
Need help with formatting of collected data

My goal is to automatically name computers in the organization using a noscript. The only data required for the naming is Locale-ModelType-CurrentUserName (i.e. us-mbp-kunkmaster.flex)

The furthest I have gotten in the noscript is actually pulling the data that I need. What I cannot figure out is how to format that data into the end result. For example, the noscript in its current form will echo "MacBookPro". However, I want that to be translated to "mbp". Or if it echos "MacBookAir", that translates into "mba". I just cannot figure out the if/then as when I create those commands, the noscript errors out.

I will tip anyone that can solve this for me as I will also use it to learn how to automate several other things.

#!/usr/bin/env bash

# get currently logged in user
user=$( /usr/bin/stat -f "%Su" /dev/console )
echo "Current user is - $user"

# Get the Model of the Machine
model=$(system_profiler SPHardwareDataType | awk '/Model Name/ {print $3 $4}')
echo "Machine type is - $model"

#Get Locale of Machine
locale=$(locale | awk '/LANG/ {print $1}')
echo "Locale is - $locale"

https://redd.it/10hf2fz
@r_bash
Text separated by new lines acts different than text separated by spaces

I have this noscript that finds and deletes unwanted text (badwords) in directory names, subdirectory names and file names in the current working directory. The unwanted text is in the file /home/oops/badwords.txt

The noscript works as it should when the badwords in /home/oops/badwords.txt are all on seperate lines:

oops@8740w:~$ cat badwords.txt
CDRip
YIFY
AAC_5_1
WEBRip
YTS_MX

When I run the noscript those words are all deleted from the folder and file names in the working directory when they are on their own lines.

However, when the badwords in /home/oops/badwords.txt are just seperated by spaces:

oops@8740w:~$ cat badwords.text
CDRip YIFY AAC_5_1 WEBRip YTS_MX

then the noscript fails and doesn't find and delete the badwords.

Here's the noscript:
*********************************************


#!/bin/bash


input="/home/oops/badwords.txt"



while IFS= read -r line

do



echo "$line"



find -name "*$line*" -print0 | sort -rz | while read -d $'\0' f; do mv -v "$f" "$(dirname "$f")/$(basename "${f//$line/}")"; done

#
#
done < "$input"


**************************************************************************

I know while IFS= read -r line is working when the text is separated by spaces because the echo "$line"

prints the badwords when they're separated by spaces

But when "$line" gets passed into the find command it doesn't find and delete the badwords.

I'm thinking I need to add a newline somehow during the read process or maybe I don't have the right syntax(?) in the read command.

It doesn't really matter to me if the text in badwords.txt is all on separate lines but there's something I'm missing here and it just bothers me that I can't find the answer.

Please, go easy on me, I'm learning this on my own and know I haven't used the right words. Tried shellcheck but it doesn't see a problem.

I'd much appreciate a kick in the right direction.

https://redd.it/10hgw08
@r_bash
No output

Hi guys im new to shellbash , im running this on ubuntu virtual box ,When i run my program I don't get any errors. The program asks me for a number i write it in and then it just stops, could anybody tell me why the digits are not printing? thanks in advance

program

https://redd.it/10hsrpe
@r_bash
read -a variable <<< $dataset (Change delimiter)

The data set I am working with has spaces.


Structure:
SUBURB TOWN NUM1 NUM2

Since Suburbs and Towns often have Spaces in i have chosen to use the typical CSV structure.

VALLEY VIEW,JONES TOWN,2032,2033

Using the read command I can easily save it into variables using the dataset but the issue is that read -a defaults to a space character as the delimiter, so the above becomes...


${variable[0\]} is VALLEY
${variable[1\]} is VIEW,JONES
${variable[2\]} is TOWN,2032,2033
${variable[3\]} is null


I need to use the comma character as the delimiter so I can get the following...


${variable[0\]} is VALLEY VIEW
${variable[1\]} is JONES TOWN
${variable[2\]} is 2032
${variable[3\]} is 2033

I tried using ...

read -d "," -a variable <<< $dataset

&#x200B;

No difference. Any one got some idea?

https://redd.it/10i1iiu
@r_bash
How to uses pipes with an executable that does not support shebang line?

wasmtime does not support shebang; see https://github.com/bytecodealliance/wasmtime/issues/3715, https://github.com/bytecodealliance/wasmtime/issues/5614.

So when we do this


#!/usr/bin/env wasmtime
(module
;; ...
)

this happens

$ ./demo
Error: failed to run main module ./demo

Caused by:
0: if you're trying to run a precompiled module, pass --allow-precompiled
1: expected (
--> ./demo:1:1
|
1 | #!/usr/bin/env wasmtime
| ^

So far I have tried

#!/usr/bin/sh

wasmtime run /dev/stdin <<END
(module
;; ...
END

and


#!/usr/bin/sh

cat >foo.wat <<END
(module
;; ...
)
END

wasmtime run foo.wat

to no avail.

What I am trying to do is create a WebAssembly Native Messaging host that functions the same as C, C++, Python, JavaScript engine Native Messaging hosts.

Thanks in advance for your help.

https://redd.it/10i09se
@r_bash
Newline & carriage return not behaving like I expect with echo command.

I'm trying to make a one-line terminal command to append an alias to my .bashrc file. I want 2 returns/newlines/carriage returns so the file isn't a pain to read, then a commented "noscript" explaining the line's function, then the alias command.

I want it to look like:

#last line of the file


#Title/explanatory statement
alias quickbackupC1='rsync -ac --info=progress2 --delete /home/user/{Downloads,Desktop,Documents,GitHub,Pictures,Videos} /media/user/CRUCIALX6-1'

Here's what I came up with:

echo "\r\r#Alias for quick backup to drive 1\ralias quickbackupC1='rsync -ac --info=progress2 --delete /home/user/{Downloads,Desktop,Documents,GitHub,Pictures,Videos} /media/user/CRUCIALX6-1'" >> /home/user/.bashrc

All this does it paste everything inside the double quotes into the file like:

#last line of the file
\r\r#Alias for quick backup to drive 1\ralias quickbackupC1='rsync -ac --info=progress2 --delete /home/user/{Downloads,Desktop,Documents,GitHub,Pictures,Videos} /media/user/CRUCIALX6-1'

I've tried both \n and \r to insert blank lines. Where am I going wrong?

https://redd.it/10i6uoa
@r_bash
Why are my strings not concatenating? The current output is just "viewers!"
https://redd.it/10ic7w0
@r_bash
neovim on gitbash

im using gitbash as my terminal and i want to install neovim to it i already got vim and it works fine but hot to install neovim !!

https://redd.it/10iixqh
@r_bash
Compiling .sh files

Hey all , my task is to run a noscript ive made using makefile,I know that compiling .cpp files is with g++, but is there a command for compiling .sh files?

i just want to do something like g++ filea.sh fileb.sh \-o run

but this command returns following errors:

/usr/bin/ld:lab03a.sh: file format not recognized; treating as linker noscript

/usr/bin/ld:lab03a.sh:5: syntax error

collect2: error: ld returned 1 exit status

https://redd.it/10ijqdk
@r_bash
How can I chain commands together in bash that send each one into the background? Keep getting syntax errors, and I'm wondering if there's a way.

Here is an example of what I am trying to do:

less .bashrc &; less .bashrc &

less .bashrc & && less .bashrc &

Both give syntax errors at ; or &&, respectively. Is there a way to do this that can work in chained commands like this?

https://redd.it/10iqwh0
@r_bash
Is polling in a separate noscript the correct approach to terminate process substitution

wasmtime does not support using shebang then raw WAT for the noscript body, so we can't do


#!wasmtime

(module
;; ...
)


I've cobbled together a workaround using a separate noscript. Is the the correct approach to proceed?

nmcwat.sh

#!/bin/bash
# https://www.reddit.com/r/bash/comments/10i09se/comment/j5blsrw/

noscript='
(module
;; ...
)
'

./killwasmtime.sh &
./wasmtime
<(printf '%s' "$noscript")


killwasmtime.sh

#!/bin/bash
while pgrep -f nmcwat.sh > /dev/null
do
sleep 1
done
killall -9 wasmtime
exit 0

https://redd.it/10ixjx2
@r_bash
Grep for multi-character patterns in random order

Is there a way to grep for multiple patterns, each with several characters, in random order?

What I am trying to do would be something like

echo -e $inputline1 $inputline2 | grep [pattern][another_pattern]

However, that returns all lines containing any character in pattern right before any character in another_pattern, while I need something that returns all lines that match either pattern another_pattern or another_pattern pattern, preferably without nested greps.

https://redd.it/10iz8ke
@r_bash