r_bash – Telegram
How can one reliably output text, if it contains text from variable expansions?

I want a command to easily print out text, that may include text from a variable expansion.
The bash command echo fails for FOO=-n and BAR=bar:

$ echo "$FOO" "$BAR"
bar$

There is printf, but there you always need to pass a format string, which to me seems to burdensome. One might try a function definition:

$ myecho () { printf %s "$@" ; }
$ echo $FOO $BAR
-nbar$ # space between arguments is missing.

There must be some ready to use solution, right?

https://redd.it/1dgiz6d
@r_bash
Why does ">> " result in ambiguous redirect

In a folder i have 3 files : file1 file2 file3

Doing "date >> ./
" Causes error "ambiguous redirect.

https://redd.it/1dh4fpd
@r_bash
Script for doing the command line labor in making and adding to a github repository

It's very simple as far as software is concerned, mostly just designed it for myself just because i think making commits to github is kinda annoying:

https://github.com/LEDparty/lazy-commit

Tested and works like it should.

https://redd.it/1dhd2zb
@r_bash
MarCLIdown: A decent way to read markdown files directly in your linux terminal.

MarCLIdown (WIP) is a minimalist Bash program that prints a Markdown file with a beautiful, human-readable monochrome output, featuring interactive images, hyperlinks, emails, and references, as well as noscripts, emphasis, strikethrough, highlighted text, and Unicode characters for easy recognition of elements such as lists, checkboxes, collapsible sections, notes, etc.

https://preview.redd.it/5fz9y399y07d1.png?width=1365&format=png&auto=webp&s=d86457db474f9f75c760ede62ab877fe6fe284d9

I don't have much knowledge of programming, so there's still a lot to improve in the code, as well as finishing the planned features.

What do you think? And what extra formatting could this support? Any good github flavor feature I forgot about?

https://redd.it/1dhl7ij
@r_bash
Help with noscript to format markdown tables

Hi, I recently made this post asking for help on how to make hyperlinks in a markdown file appear beautifully in the terminal, as I was making a program similar to glow, I've made a lot of progress (which you can see here) since then, but I just couldn't handle formatting the markdown tables, does anyone know how this could be done using only native linux tools?

https://redd.it/1dhlerj
@r_bash
Have you ever written a full on application in Bash? What was it?

I'm a very old hat programmer. C++ was newfangled stuff and nobody had ever spoken the word "Javanoscript" when I first learned how to code Hello World. Bsh/Bash was the first language I learned, and we called it "terminal programming" back then and not noscripting.


To this day its my go to if I need to write a linux-portable application that doesn't engage with the hardware enough to require C. I recently "finished" a program for controlling an entire network of remote Varnish server clusters, written in just under 2000 lines. It uses a pull-store-flag-edit-push-versioncontrol schema with 4 levels of granularity in managing .vcl files, and has remote tools built in for generating and pulling logs, modifying inline C include files, and controlling all the cache parameters. It even has a fancy toggling system that lets a non-VCL nerd enable and disable all the special modules, and its own Help menu.


I wrote this beast because I'm the only resident Varnish guru in our devteam, and I needed something simple that other administrators can use to control and maintain the system if I got hit by a bus. At its current line count, and with 28 menus I'm about 80% sure its the biggest Bash program I've written in my life. That got me wondering what kinds of things other people have written as their Magnum Opus.

https://redd.it/1dhsf7u
@r_bash
Site that returns protocol that can be used from the command line

Is there a site similar to ifconfig.me that you can curl so that it returns the protocol it was hit with? I.e. curl http://example.com should return http somewhere in the response and curl https://example.com should return https.

https://redd.it/1di8umt
@r_bash
Write to file keeps service restarting

I am trying to write a simple multi-line value to a file.

I've noticed as I watch the processes, and the logs, whenever I add that particular code and re-start my service, it loops over and over again, instead of running once and then waiting for the timer to re-activate it.

cat ${dir}/${file}.json << EOF
{
"id": "${item_id}",
}
EOF


I then execute

systemctl --user start my_service_name.service


And then loop begins. As soon as I remove that particular set of code and re-execute, then the noscript only runs once, and then waits 15 minutes for the .timer to call it again.

I've tried both cat and tee hoping one or the other would work.

https://redd.it/1did9c7
@r_bash
messed up configuration

Hi

i am running tumbleweed and messed up my bashrc (i think).

I followed this guide:

https://christitus.com/beautiful-bash/

i recognized afterwords that a comment says "this wont work on opensuse".



now, everytime i start my terminal, i get an "bash: /home/*user*/.bashrc: Permission denied"


is there a simple way to fix that? or do i have to reverse engineer the sh noscript?

https://redd.it/1djf1od
@r_bash
Anyone help me understand why this string fails regex validation?

This code outputs "bad" instead of "good" even though the regex seems to work fine when tested on regex101.com . Does anyone understand what is wrong?

#!/usr/bin/env bash

readonly serverVer="1.2.3.4"

if [[ "$serverVer" =~ ^(?:(\d+)\.)?(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$ ]]; then

echo good

fi

echo bad

https://redd.it/1djft6r
@r_bash
How would you learn bash noscripting today?

Through the perspective of real practise, after years of practical work, having a lot of experience, how wold you build your mastery of bash noscripting in these days?

*which books?
*video lessons?
*online courses?
*what kind of pet projects or practices?
*any other advices?

Thank you!

https://redd.it/1djhccz
@r_bash
How to extract certain text from local html files in ubuntu

I have several HTML files saved locally. How can I extract numbers that start with "-" from all of them and save each number in a separate line in a new file? For example, the numbers are formatted like this: - 74345. I want each of these numbers to be placed on a new line in the output file.

https://redd.it/1djqcjs
@r_bash
CLI lightweight 3D printer progress viewer noscript
https://redd.it/1dk0sgj
@r_bash
source file counter variable

My post keeps getting removed for my code.

My source file has 4 line is such as

img_1=file1

img_2=file2

I'm trying to write a noscript with a counter to "ls -lh $img_1".... be easier to explain if I could post my code

https://redd.it/1dl8zkx
@r_bash
Need Help Sorting Files by Hashing in Bash Script

I've been trying to sort files in a folder by comparing them to a source directory using BLAKE2 hashing on my unraid server. The noscript should move matching files from the destination directory to a new folder. However, it keeps saying "Destination file not found" even though the files exist.

### Here’s the noscript:

```bash
#!/bin/bash

# Directories
source_dir="/path/to/source_directory"
destination_dir="/path/to/destination_directory"
move_to_dir="/path/to/move_to_directory"

# Log file
log_file="/path/to/logs/move_files.log"

# Function to calculate BLAKE2 hash
calculate_hash() {
/usr/bin/python3 -c 'import hashlib, sys; h = hashlib.blake2b(); h.update(sys.stdin.buffer.read()); print(h.hexdigest())'
}

# Ensure destination directory exists
mkdir -p "$move_to_dir"

# Iterate through files in source directory and subdirectories
find "$source_dir" -type f -print0 | while IFS= read -r -d '' source_file; do
# Print source file for debugging
echo "Source File: $source_file"

# Calculate hash of the file in the source directory
source_hash=$(calculate_hash < "$source_file")

# Calculate relative path for destination file
relative_path="${source_file#$source_dir}"
destination_file="$destination_dir/$relative_path"

# Print destination file for debugging
echo "Destination File: $destination_file"

# Check if destination file exists
if [ -f "$destination_file" ]; then
# Print hash calculation details for debugging
echo "Calculating hashes..."
destination_hash=$(calculate_hash < "$destination_file")

# Log hashes for debugging
echo "$(date +"%Y-%m-%d %H:%M:%S") - Source Hash: $source_hash, Destination Hash: $destination_hash" >> "$log_file"

# Compare hashes
if [ "$source_hash" == "$destination_hash" ]; then
# Move the file to the new directory
mv "$destination_file" "$move_to_dir/"

# Log the move
echo "$(date +"%Y-%m-%d %H:%M:%S") - Moved: $destination_file" >> "$log_file"
fi
else
echo "Destination file not found: $destination_file"
fi
done

echo "Comparison and move process completed."

https://redd.it/1dm775e
@r_bash
learning file permissions, what is the "owner" "group" and "other"?

hello i'm trying to learn and understand file permissions in bash, and to what i understand there are 3 "categories" in bash?

owner, group and other?

what do these things mean? what does owner mean? is that strictly the user that made the file or can the owner of a file give ownership of that file to another user?

what are groups?

and what are "other"? what does that mean?

thank you

https://redd.it/1dmfkes
@r_bash
What's the most elegant way to achieve this?

So I have a wine program I'd like to run and also a wine prefix I'd like to run that program in. Both have long paths.

Should I alias them both in .bash_aliases, then call them within a noscript and call it a day? Preferably something I could also bind to a key easily.

Sorry if this question is dumb.



https://redd.it/1dmzfe9
@r_bash
bashbro - New Software Release (rework of bashttpd)

Newly released bashbro - it's Bash-based web file browser that allows you to remotely browse, stream, view documents and save files via your web browser. Super easy to use, try it!!

https://github.com/victrixsoft/bashbro/

https://redd.it/1dndldo
@r_bash
Counterintuitive word splitting

I've recently already made a post about word splitting, however, this seems to be another unrelated issue that I again can't seem to find any answers. Consider this setup:

$ #!/bin/bash
$ # version 5.2.26
$ IFS=" :" # space (ifs-whitespace), colon (ifs-non-whitespace)
$ A=" ::word:: " # spaces, colon, "word", colon, spaces
$ printf "'%s'\n" $A
''
''
'word'
''

As you can see, printf got 4 arguments, as opposed to 3, what I would've expected. First, I though my previous post might be related, however, adding another instance of `$A` to the end makes it 8 arguments, exactly double, so it's not related to stripping trailing "null arguments".

Why does this happen? Is there a sentence in the man page that explains this behavior (I couldn't parse it from the section about word splitting :'D)

Edit: I tested the following bourne-like shells:

bash
bash -o posix
dash
ksh
mksh
yash
yash -o posix
posh (policy-compliant ordinary shell)
pbosh (schilytools)
mrsh (by Simon Ser)

ALL of them do it exactly the same, except mrsh (it's doing what I expected). However, mrsh is quite niche and rather a hobby project by someone, so I wouldn't take that as any authority.

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