r_bash – Telegram
Could someone explain the logic behind a find command which renames files for me?

I have the following command which I use from time to time (via Google):

find /the/path -depth -name "*.abc" -exec sh -c 'mv "$1" "${1%.abc}.edefg"' _ {} \;

I know that it works, and I know that I need the underscore and the curly brackets at the end before the escaped ;. Without them, the command ends up only giving the extension.

*Why* are the underscore and the curly brackets needed? What exactly do they do in this context? The `bash -c` command takes the `{}` as the argument to give you `$1`, but where does the underscore fit in?

If you have a link to where this is explained, it would be great.

https://redd.it/1cw9iuo
@r_bash
Complete noob having issue with strange url in terminal

Hi my dudes,

I try to avoid the terminal as much as I can, but sometimes you're just forced to build or run some command line application. E.g., I would like to run the following command to convert an iso to chd:

#!/bin/bash

for file in *.iso; do chdman createcd -i "${file%.*}.iso" -o "${file%.*}.chd"; done

This does, in fact, work as intended. However, when I look at the terminal output, I notice the following:

#/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/yb85/scantailor-advanced-osx/HEAD/install.sh)"

I honestly have no clue what this is supposed to signify. I suppose some odd custom ssl connection setting or something? Scantailor Advanced is a program I did install at some point, but how is it that anytime I use #!/bin/bash I am presented with this url of a program I am not even working with in that moment? It seems to me this is not how things should be setup. Thus, my question, how can I restore this for it to just work normally without this url being involved in anything?


Hope someone can advise on this, would be much appreciated!

https://redd.it/1cwg3vp
@r_bash
Can anybody help me to write this bash noscript?

I have found this command to compress PDF files and it works. But it is too long for me to memorize it.

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed_PDF_file.pdf input_PDF_file.pdf

I want to make a bash noscript like this:

compress input.pdf output.pdf

So if it is a simple question, sorry. I've been using linux for about 5 months.

https://redd.it/1cx25bg
@r_bash
use variable in variable while looping

Hi,

In a larger noscript I need to loop through a list of predefined items. Underneath a simplified working part of the noscript:

#!/bin/bash
totalitems=4

# define integers
item[1]=40
item[2]=50
item[3]=45
item[4]=33

# start with first
counter=1

while [ "$counter" -le "$total
items" ]
do
echo "${item$counter}"
let counter+=1
done

However I'm curious if the same is possible without using an array. Is it even possible to combine the variables 'item' and 'counter', e.g.:

#!/bin/bash
totalitems=4

# define integers
item1=40
item2=50
item3=45
item4=33

# start with first
counter=1

while [ "$counter" -le "$total
items" ]
do
echo "$item$counter" <---
let counter+=1
done



https://redd.it/1cx6iqw
@r_bash
why in the server where I upload dirs and files I can not do mkdir -p dir1 dir1/subdir1/ dir1/subdir2/ etc?

Hi. will there be bash in the server? the server mean place where I use sftp user@server.team

in local I can do mkdir flag -p ...

Thank you and regards!

https://redd.it/1cxdscs
@r_bash
TIL: Prompt in "read -p prompt" goes to stderr

It is documented in man bash:

>\-p prompt
>
>Display prompt on standard error, without a trailing newline, before attempting to read any input. The prompt is displayed only if input is coming from a terminal.

but not in help read:

>\-p prompt
>
>output the string PROMPT without a trailing newline before attempting to read

So, echo -n prompt; read is NOT equivalent to read -p prompt. The former should be preferred, because you're free to send the prompt to either stdout or stderr without side effects. Even though read -p prompt 2>&1 would send the prompt to stdout, error messages produced by read would go there as well.

https://redd.it/1cxkocc
@r_bash
Ffmpeg, ranger & concatenating

I've been using these noscripts with mpv for years which makes it simple to chop up, crop & encode video from from mpv. add in a file delete noscript and I can chop up, crop & encode video, and delete the original from mpv just using the keyboard, which is nice.

what they don't allow me to do is stitch video back together, like this.

I use ranger to launch mpv and would be nice if I can use that to concatenate.

I currently have this in my rc.conf:

map xc shell for f in %s ; do echo "file $f'" >> mylist.txt; done

map xj shell ffmpeg -f concat -safe 0 -i mylist.txt -c copy complete.mp4

it kinda works a bit but feels janky, I need to delete files and rename stuff, and have no idea what I am doing when it comes to noscripting stuff.

ideally I would select %s files as I do with the space bar on ranger, be able to specify the output file name and not have to worry about duplicate mylist.txt files.

any ideas?

is this the right place for this kinda question? I'm new here

https://redd.it/1cxmx7y
@r_bash
ifempty: data protection wrapper for mkfs.X tools

When you try to format some non-empty storage with mkfs.ext4, it asks for a confirmation:

> truncate -s 100m 1.img
> mkfs.ext4 1.img
mke2fs 1.46.5 (30-Dec-2021)
Discarding device blocks: done
Creating filesystem with 25600 4k blocks and 25600 inodes

Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

> mkfs.ext4 1.img
mke2fs 1.46.5 (30-Dec-2021)
1.img contains a ext4 file system
created on Wed May 22 02:13:10 2024
Proceed anyway? (y,N) n

Not all mkfs tools act like that. For example, mkfs.fat (and aliases mkfs.msdos, mkfs.vfat), mkfs.exfat, mkfs.udf, mkfs.ntfs, mkfs.minix just format everything without any checks.

My noscript can be used to add the non-empty check to such "dumb" tools. There is a detailed README in the repo

https://github.com/slowpeek/ifempty

https://redd.it/1cxlwkf
@r_bash
Whenever I run the 'find' command, it seems to replace Chinese characters with "?" marks. The 'ls' command does not do this. How do I get 'find' to behave?

user@server$ find . -type f

...

????????????????? www.HDBTHD.com???????????????[???????????????].Stargate.1994.1080p.BluRay.x265.10bit.DTS.mkv

...

Meanwhile, ls correctly gives me: 【高清影视之家发布 www.HDBTHD.com】星际之门[简繁英字幕].Stargate.1994.1080p.BluRay.x265.10bit.DTS.mkv.

What gives?

https://redd.it/1cxq2ci
@r_bash
Starship Prompt showing vertical line in the prompt graphic.

I recently started using Starship to configure my bash prompt. One thing I noticed are these vertical lines that appear when the shape of the prompt graphic changes. I have a slight orange line where it changes to a point and a slight blue line when it changes to a half circle. Is there a way to fix this?

https://preview.redd.it/frbwxp0vd12d1.png?width=291&format=png&auto=webp&s=af37adcc3788d62ff210fc3a3de4f77e00b5e418



https://redd.it/1cya8tt
@r_bash
is there a shortcut for jump to start of a command and other for jump to end of the same command?

Hi!. sometimes I wrote long command for 4 lines and repeat the command and I' d like to know if there is a shorcut for move the prompt to start of the command.

for example:

~/path/$ montage * -tile 3x2 -shadow -geometry 200x200+5+5 -noscript '\nEmisiones del día miércoles 22 Mayo 2024\nentre 01 y 04:30hs.\nE.E.G. cada 7 minutos y de 30 seg. de duración.\nModerado Humo y moderado Olor\nEn aumento con el paso de las horas' -pointsize 12 -set label '%f\n%wx%hpx\n%[exif:DateTime]hs' -quality 90 ../catalogo3.jpg

Thank you and Regards!

https://redd.it/1cye9mu
@r_bash
Could someone explain this behaviour?

> bash -c 'ls -l "$1"; sudo ls -l "$1"' - <(echo abc)
lr-x------ 1 pcowner pcowner 64 May 24 02:36 /dev/fd/63 -> 'pipe:679883'
ls: cannot access '/dev/fd/63': No such file or directory

https://redd.it/1cz734d
@r_bash
is there a difference between "ctrl /" and "ctrl shift -" ?

hello, i'm trying to learn the keyboard shortcuts for bash, and i was learning about how to undo something i did in the terminal text line and i heard about

"ctrl /" which undoes something you did in your text line

then i heard about

"ctrl shift -" which ALSO undoes something you did in the text line apparently

is there any difference between the two keyboard shortcuts? or are they both the same?

thank you

https://redd.it/1czgu8h
@r_bash
BASH syntax help

Hi folks.

I am struggling with my BASH syntax. I am trying translate some commands from the cli, in to a noscript. I am capturing input variables, to be used within an array, however for the life of me I cannot figure out where I am messing up.

Here is the cmd, from the cli:-

`grep -E $"date"\|HTTP/[0-9]*\.[0-9]+\"\s$status' *`

Here is the noscript, in which I began using two greps, as doing it like the above, using `'pattern1\|pattern2'` didn't work, even on the cli:-

1 #!/bin/env bash
2
3
4
5 echo Please enter the day, month, year and time you wish to search \(eg:- 6 12/Nov/2023:13:24 or 12/Nov/2023:01:24\) [Enter]:
6 read date
7
8 echo Please enter the http status code you wish to search \(eg:- 200\) [Enter]:
9 read status
10
11 echo Please enter the server name you wish to search \(eg:- SERVER.DOMAIN\) [Enter]:
12 read server
13
14 search="$(grep -a '$date' log-file-2024* > /tmp/first.txt && grep -a 'HTTP/1.0" "$status" first.txt > /tmp/"$server"_access_logs.txt)"
15
16 ssh user@"$server" cd /SOME/RANDOM/DIR; timeout -k 2 20 "$search"

The error I receive when running `bash -x` [`noscript.sh`](http://noscript.sh):-

`noscript.sh: line 14: first.txt > /tmp/first.txt: No such file or directory`

... then my ssh command sits idle, without having any variables successfully added, like so:-

`+ ssh user@ cd /some/random/directory`

I have tried various approaches to my variables, but I can never get them to be called, correctly.

https://redd.it/1czm64i
@r_bash
Found this on twitter. Felt worth sharing
https://redd.it/1czrlxt
@r_bash
how to bash noscript output to vim

So I created a custom bash noscript echos some question to read input from user for configuration purpose and later echo $(pwd)/filename.sh. When the noscript outputs the path + filename, I would like to open vim with the output. I tried pipe the output to vim input, but somehow the bash noscript doesn't appear to echoing anything to read input. Anyone wanna give me some idea how and why? For now, my assumption is that when noscript is executed where both echo and read is operated, echo is redirected to vim (which why any echo from noscript doesn't show output on terminal) and read waits for my input. If I can redirect the echo back to the terminal, then the expression works as expected. But I do not know how. Maybe I need to use either `>` or `>>` to redirect `echo` output to shell?

`$ noscript-gen.sh | xargs vim # failed`

https://redd.it/1czta63
@r_bash
Image Conversion Bash Script

# Image Conversion Script

## Overview

This noscript provides a comprehensive solution for converting image files between various formats using ImageMagick and FFmpeg. It supports a wide range of input and output formats, including PNG, JPG, WEBP, JFIF, ICO, TIFF, BMP, and GIF. The noscript is designed to be efficient, easy to use, and versatile, catering to the needs of users who require reliable image format conversion.

## Target Audience

This noscript is intended for:
- Developers and IT professionals who need to batch convert image files as part of their workflow.
- Graphic designers and content creators who frequently work with different image formats.
- System administrators looking for a robust solution to automate image conversion tasks.
- Any user who requires a straightforward, command-line based method to convert image files.

## Features

- Multiple Input and Output Formats: Supports PNG, JPG, WEBP, JFIF, ICO, TIFF, BMP, and GIF formats for both input and output.
- Batch Processing: Converts multiple files in a directory, saving time and effort.
- Output Directory: Stores all converted files in an output directory within the noscript's directory, ensuring a clean and organized workspace.
- Dependency Check: Verifies the presence of necessary dependencies (ImageMagick and FFmpeg) before execution.
- Interactive Deletion: Offers an option to delete the original files after conversion.

## Usage

To use the noscript, follow these steps:

1. Ensure Dependencies: Make sure ImageMagick and FFmpeg are installed on your system.
2. Run the Script: Execute the noscript in the directory containing your image files.
3. Select Output Formats: When prompted, enter the desired output formats (comma-separated, e.g., jpg,png,ico).
4. Conversion: The noscript will convert the files and store the output in the output directory.
5. Optional Deletion: Choose whether to delete the original files after conversion.

## Why This Script?

This noscript stands out due to its:
- Versatility: Unlike many other noscripts that support limited formats, this noscript accommodates a broad range of image file types, making it a one-stop solution for various conversion needs.
- User-Friendly Design: With clear prompts and organized output, the noscript ensures a smooth user experience.
- Batch Processing Capability: It efficiently handles multiple files, streamlining the conversion process and enhancing productivity.
- Professional and Robust Approach: The noscript includes thorough checks and error handling, ensuring reliability and robustness in diverse environments.

## Conclusion

This image conversion noscript is a powerful tool designed for users who need a reliable and versatile solution for converting image files between various formats. Its wide range of supported formats, ease of use, and efficient batch processing make it an essential utility for developers, designers, and system administrators alike.

## Download the noscript

You can download the noscript here on my GitHub page.

https://redd.it/1d08ada
@r_bash
GOTCHA: The arithmetic form that can kill your noscript

Q: Why use a=$((a-1)) when you can say ((--a))?

On the surface, they both do the same thing (decrement a), but the latter saves quite a few characters with long variable names, and saves you from a frustrating debugging session if you typo the name on the LHS of the assignment.

However, there's an additional wrinkle to the arithmetic command form that can interact unexpectedly with set -e, that the assignment form never triggers. It crops up when a=1, and is documented in *The Fine (bash) Manual*:

>((expression))

>The expression is evaluated according to the rules described below under ARITHMETIC EVALUATION. If the value of the expression is non-zero, the return status is 0; otherwise the return status is 1.

Which is why this noscript:

#!/usr/bin/env bash
errexit() {
printf "ERROR: %s:%s\n" "${BASH
SOURCE1}" "${BASHLINENO[0]}"
exit 1
}
trap err
exit ERR
set -e

a=1
a=$((a-1))
echo "a=$a"

a=1
((--a))
echo "a=$a"

outputs this:

a=0
ERROR: test-arith.sh:14

and why your set -e noscript may be failing almost at random, when evaluating seemingly-innocent math.

If you insist on using set -e across all your noscripts, you really want to NOT use the ((...)) form except where the return status is ignored (see the set -e documentation for details on that), or if you're absolutely sure that the expression in the form never evaluates to 0, or if you're willing to do something like this:

...
set +e
((...)) # avoid abend on 0
set -e
...

The assignment form is more typing in general, but fewer WTFs (unless you typo'd the assigned name).

https://redd.it/1d09n3b
@r_bash
bracketed-paste doesnt work sometimes. Anyone has this problem?

I have bracketed-paste enabled:

> bind -v | grep paste
set enable-bracketed-paste on

but it does not always work! Sometimes when I paste a command with a trailing newline into my terminal, it runs right away. But if I paste it once more right away, it does not run, just like it should with bracketed-paste enabled.

Any idea would could be wrong? It is bash 5.1.16 in ubuntu 22.04. The terminal is konsole.

---

I recall using the feature since ubuntu 18.04 (enabled with .inputrc). It never failed for me in ubuntu 18.04 (bash 4.4) and 20.04 (bash 5.0).

https://redd.it/1d0da66
@r_bash
Clean up FF bookmarks file.

I don't know if any you have ever seen the disgraceful steaming pile of shit garbage html that firefox shits out when you ask it to export your bookmarks, but it is truly a right and goodly fucked up mess.

Have any of ya'll ever heard of or seen a noscript or something to clean that garbage file up into something resembling sensible?

Example...

> <DT><A HREF="https://moviesjoy.to/" ADD_DATE="1681307349" LAST_MODIFIED="1681307349" ICON_URI="fake-favicon-uri:https://moviesjoy.to/"