r_bash – Telegram
What's a good project to step up my bash game?

Been on linux for a few years, the command line is not unfamiliar to me but I would still like to learn more. Any good projects to force me to learn?

https://redd.it/1dbd0lq
@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/1dc1j8w
@r_bash
what is the "ctrl i" shortcut?

hello, quick question

i was experimenting and i clicked "ctrl i" while in bash and it took the text i already put into the terminal and put ".save" at the end

what does this eman?

what is the "ctrl i" shortcut? what does it do?

thank you

https://redd.it/1dbpe7h
@r_bash
Bash history across different terminal sessions.

I use tillix for having multiple terminal windows open. After using different commands in different terminal windows, I checked bash history and it shows only some commands.

I thought bash history is tied to the user and not to the terminal session. What’s the probable explanation as to why not all the commands from all terminal sessions show in in bash history? I am using popOS!

https://redd.it/1ddcykx
@r_bash
Script stops when a command is run

I'm trying to run a bash noscript during which I move to a directory to run the “npm audit” command. This command seems to stop the execution of the current noscript.



The command :

npm audit --json > “$OUTPUT_FILE”

I had the same problem on Windows. The solution I found was to run the command in another instance of cmd using the command :

cmd /c npm audit --json > “%OUTPUT_FILE%”



The bash equivalent seems to be :

bash -c “ npm audit --json > ‘%OUTPUT_FILE%’

But that didn't change anything. Does anyone have any idea what's wrong?

https://redd.it/1ddh009
@r_bash
Select output by line similar to previous commands

Just like you can use the arrow keys to scroll through previous commands, is there a way to do the same for each line of output? So I don’t have to copy or type a certain value from a list of values every time I want to use it in my next command.

https://redd.it/1ddj2o0
@r_bash
mkdir with variables

I'm backing up my movie collection to my Plex server, which is running on Ubuntu Server LTS 22.04

I'm trying to write a bash noscript to create the directory and move the files over.

This is my code so far:
```
#!/bin/bash

movie="[Movie name] ([Year]) - [resolution] {imdb-[IMDb code]}"
file=$movie.mp4
path="\"/mnt/usb1/Movies/$movie\""
mkdir $path
```

But I get an error whenever trying to run it because it tries splits the directory up to a new one whenever it encounters a space, despite including double quotation marks in the "path" variable.

*The text in square brackets is only like that for the purpose of this example

Where am I going wrong?

https://redd.it/1ddp700
@r_bash
what is the command for open Browser from bash shell?

Hi, I use command whereis for get dirs of browsers, so
what is the command for use that output of whereis?
for Falkon browser whereis says it is in /usr/bin/falkon
for Chromium whereis says /snap/bin/chromium and for FF the last same snap bin.

when I put snap bin chromium bashshell angry with me and complete the screen with lots of words... sorry my no EN, so whitch will be the command for open chroium from bash shell

Thank you and Regards!

https://redd.it/1ddrqbs
@r_bash
Cannot kill process 684 even with -9 option as sudo. Why is this the case?

ubuntu@ip:~$ ps aux | grep configurable-http-proxy
root 684 1.3 2.3 598796 47532 ? Ssl 03:28 0:00 node /usr/local/bin/configurable-http-proxy --ip --port 8000 --api-ip 127.0.0.1 --api-port 8001 --error-target http://127.0.0.1:8081/hub/error
ubuntu 802 0.0 0.1 7016 2304 pts/0 S+ 03:28 0:00 grep --color=auto configurable-http-proxy

When I ran the command, nothing happens. I ran the ps command again and I still see the process as active. Not sure how to kill it.

https://redd.it/1ddx7ic
@r_bash
Weird exit status behaviour.

I thought by default, when bash's exit builtin fails, it will not alter the current exit status. Confirmed by these cases:

$ bash -c 'exit 14'
$ exit 1 1
$ echo $?
14
$ :|exit 99
$ exit 2 2
$ echo $?
99

However, the behaviour is different when there was no previous command, in other words, in a newly spawned shell (where the initial exit status is 0).

$ exit 42 42
$ echo $?
1

Why does that happen? And more importantly, what could be the rationale behind this?

Also, somewhat related, exit's argument handling is weird. It only fails (and doesn't quit the current shell) when the first argument is a valid 64 bit number (up to leading&trailing whitespace) and there's at least one other argument (any string) after it. However, when the first argument is not numeric according to the aforementioned rules, it doesn't matter how many arguments you put, it will print an error and exit. It also doesn't quit the shell on --help as the 1st arg, however, this does set the exit status to 2.

https://redd.it/1de0a3n
@r_bash
bash noscript `sed` help

Hello, I am a college student working on a summer project, but I feel like I have been stuck for too long on this one thing.

**TLDR:** I am working on a bash noscript and am having issues with \`sed\` not putting markdown for an indented bullet point in front of the line for any ports it finds.

So I am trying to work on a bash noscript and I have been stuck on part using \`sed\` for two weeks, so I come to you all for help. So I am trying to search through an nmap scan that I have happening earlier in the noscript, and add the markdown for an indented bullet point to the port lines. If I understand correctly I should be able to use regex as the searching pattern in \`sed\`, but I have been able to get every other thing I need working except for this one.

I will put a bunch of lines I have tried at the bottom so maybe you can see my thinking/attempts, but I have 2 different theories as to why what I am trying isn't working. Oh, and with the fun 3rd theory of me missing something simple and obvious.

1: I believe \`sed\` looks at \`\*\` as whatever character is right before it? So maybe because I am using that as my bullet point markdown it's thinking its a space? But things still don't seem to work when I replace it with a \`-\` instead?

2: I am missing something about what's needed to add regex into sed. Nothing too fancy here, I think I have tried the right (~~various~~) arguments. On its own I am pretty sure that my regex is right as I can verify that on its own.

Here are a number of the commands that I have tried so far

\`sed -e '/\[0-9\]+\\/\[A-Za-z\]\[A-Za-z\]\[A-Za-z\]\[\[:space:\]\]+open/gm/$\\t \* \\/'\`

\`sed 's/\[0-9\]+\\/\[A-Za-z\]\[A-Za-z\]\[A-Za-z\]\[\[:space:\]\]/\\t \* &/'\`

\`sed -e .....; /\^\[0-9\]\\{1,5\\}\\/\[a-z\]{3}$/s/\^/\\t \* /;\`

\`awk '/\[a-z\]\[a-z\]\[a-z\] open|\[a-z\]\[a-z\]\[a-z\] open/ {print " \* " $0}' /home/$ownerAccount/Desktop/$projectName/AaFinalDoc.txt >> /home/$ownerAccount/Desktop/$projectName/BbFinalDoc.md\`

This project is larger than anything I have tried before and because its fun I just keep adding to it after I finish the previous goal. I have historically been really bad in my programming classes but this feels fun so I don't want to give up!

I appreciate any help that any of you can give me, thank you!

EDIT: warrior0x7 pointed out I dont actually show my start and end goals, so here is an example that hopefully might help.

Nmap scan report for
PORT STATE SERVICE VERSION
8008/tcp open http?
8009/tcp open ssl/ajp13?
8443/tcp open ssl/https-alt?
9000/tcp open ssl/cslistener?
10001/tcp open ssl/scp-config?
MAC Address: 1C:53: (Google)
Aggressive OS guesses: Android 6.0 - 7.1.2 (Linux 3.18 - 4.4.1)
TRACEROUTE
1 66.90 ms 192.168.

Nmap scan report for 192.168.
PORT STATE SERVICE VERSION
8008/tcp open http?
8009/tcp open ssl/ajp13?
8443/tcp open ssl/https-alt?
9000/tcp open ssl/cslistener?
9080/tcp open glrpc?
10001/tcp open ssl/scp-config?
MAC Address: 1C:53: (Google)
Aggressive OS guesses: Android 6.0 - 7.1.2 (Linux 3.18 - 4.4.1)
TRACEROUTE
1 44.48 ms 192.168

Nmap scan report for 192.168.
PORT STATE SERVICE VERSION
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
445/tcp open microsoft-ds?
5357/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
MAC Address: D8:BB: (Micro-Star Intl)
Device type:
Aggressive OS guesses: Microsoft Windows 11 21H2 (97%)
TRACEROUTE
1 2.13 ms 192.168.

But the only thing I am looking at to alter (with this line that I am having issues with) is the ports. I already have adding markdown working for what I want to do to every other line. So that end result looks like this.

Nmap scan report for
PORT STATE SERVICE VERSION
* 8008/tcp open http?
* 8009/tcp open ssl/ajp13?
*
8443/tcp open ssl/https-alt?
* 9000/tcp open ssl/cslistener?
* 10001/tcp open ssl/scp-config?
MAC Address: 1C:53: (Google)
Aggressive OS guesses: Android 6.0 - 7.1.2 (Linux 3.18 - 4.4.1)
TRACEROUTE
1 66.90 ms 192.168.

Nmap scan report for 192.168.
PORT STATE SERVICE VERSION
* 8008/tcp open http?
* 8009/tcp open ssl/ajp13?
* 8443/tcp open ssl/https-alt?
* 9000/tcp open ssl/cslistener?
* 9080/tcp open glrpc?
* 10001/tcp open ssl/scp-config?
MAC Address: 1C:53: (Google)
Aggressive OS guesses: Android 6.0 - 7.1.2 (Linux 3.18 - 4.4.1)
TRACEROUTE
1 44.48 ms 192.168

Nmap scan report for 192.168.
PORT STATE SERVICE VERSION
* 135/tcp open msrpc Microsoft Windows RPC
* 139/tcp open netbios-ssn Microsoft Windows netbios-ssn
* 445/tcp open microsoft-ds?
* 5357/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
MAC Address: D8:BB: (Micro-Star Intl)
Device type:
Aggressive OS guesses: Microsoft Windows 11 21H2 (97%)
TRACEROUTE
1 2.13 ms 192.168.

Hopefully that helps to clarify things.

https://redd.it/1dec1ti
@r_bash
Ignore error and continue with other files

Hi all, I can't seem to use the right search words to find what I'm looking for so I am braving r/bash with my query.

I have \~70 fastq.gz files in a directory that I need to unzip. Easy peesy, right?:

gzip -d *.gz


Turns out, some of the files are corrupted and this results in an error. The command simply stops and none of the other files get unzipped. How can I skip bad files and unzip good files?

https://redd.it/1delnyw
@r_bash
Easy question

At first I'm new to noscripting and this is for sure an easy question for you but:
I have a variable with file names separated by a space, like "FileA.txt FileB.txt FileC.txt".
I simply want to move those files to another directory. How can I get those file names readable for Linux?

https://redd.it/1deya1g
@r_bash
What does ${0%/} mean exactly

I've got a noscript that creates backups of my various machines on my network. I have the .sh file located in a directory on my nas and then my machines just access the nas to run the noscript.

I was having trouble figuring out how to set the working directory to the directory that the noscript is located in so I can store all the backups in the same directory. I did some research and discovered the line:

cd "${0%/
}"

This line works and does exactly what I need but, I'd like to know what it means. I know cd and I know what the quotes mean but everything within the quotes is like a foreign language to me but I'd like to understand.

Thanks in advance

https://redd.it/1dfdjg4
@r_bash
k10s noscript feedback and next steps

I wrote a noscript to create a little CLI I dubbed k10s. I made this as a solution to more quickly open up various regional clusters next to one another in a window. I'd appreciate feedback on where to improve what I have done, as well as suggestions for any features and next steps to keep learning.

#! /usr/bin/env bash

k10s_dir=$HOME/.config/k10s
groups_file=$HOME/.config/k10s/groups

process_contexts() {
local index=0
local random=$RANDOM
local session="session-$random"
local split_times=$(($#-1))
tmux new-session -d -s "$session" \; switch-client -t "$session"

while [[ "$split_times" -gt 0 ]] ; do
tmux split-window -h -t "$session"
((split_times--))
done
tmux send-keys -t "$session:0.0" "tmux select-layout even-horizontal" C-m
for context in $@; do
tmux send-keys -t "$session:0.$index" "k9s --context $context" C-m
((index++))
done
}

save_group() {
mkdir -p "$k10s_dir"
touch "$groups_file"
local group=$(echo $@ | awk -F [=,' '] '{print $1}')
local contexts=$(echo $@ | awk -F [=,' '] '{for (i=2; i<=NF; i++) printf $i (i<NF ? OFS : ORS)}')
update_group "$group"
echo "$group"="$contexts" >> "$groups_file"
}

update_group() {
while read line; do
local group=$(echo "$line" | awk -F [=,' '] '{print $1}')
if [[ "$1" = "$group" ]]; then
sed -i "/$line/d" "$groups_file"
fi
done < "$groups_file"
}

start_group() {
while read line; do
local group=$(echo "$line" | awk -F = '{print $1}')
if [[ "$group" = "$1" ]]; then
local contexts=$(echo "$line" | awk -F = '{for (i=2; i<=NF; i++) printf $i (i<NF ? OFS : ORS)}')
process_contexts ${contexts[@]}
fi
done < "$groups_file"
}

usage() {
figlet -f slant "k10s"
cat <<EOT
k10s is a CLI that enables starting multiple k9s instances at once.

Usage: k10s [flags]

Flags:
-c, --context List of contexts to start up (e.g. k10s -c <CONTEXT_NAME> <CONTEXT_NAME> ...)
-s, --save List of contexts to save/overwrite as a group name (e.g. k10s -s <GROUP_NAME>=<CONTEXT_NAME> <CONTEXT_NAME> ...)
-g, --group Group name of contexts to start up (e.g. k10s -g <GROUP_NAME>)
-h, --help Help for k10s

EOT
exit 0
}

main() {
if [ "$#" -eq 0 ]; then
usage
fi

while [[ "$#" -gt 0 ]]; do
case "$1" in
-c | --context )
shift
contexts=()
while [[ "$1" != "" && "$1" != -* ]]; do
contexts+=("$1")
shift
done
process_contexts ${contexts[@]}
;;
-s | --save )
shift
contexts=()
while [[ "$1" != "" && "$1" != -* ]]; do
contexts+=("$1")
shift
done
save_group ${contexts[@]}
;;
-g | --group )
shift
start_group "$1"
;;
-h | --help )
shift
usage
;;
* )
shift
usage
;;
esac
shift
done
}

main $@

https://redd.it/1dffex9
@r_bash
download a website for offline use with sequential URLs

Hey everyone,I'm looking for a way to download an entire website for offline use, and I need to do it with sequential URLs. For example, I want to download all the pages from

www.example.com/product.php?pid=1

to

www.example.com/product.php?pid=100000

Does anyone know of a tool or method that can accomplish this? I'd appreciate any advice or suggestions you have.Thanks!

https://redd.it/1dfhhqj
@r_bash
open command & xdg-open command & Ubuntu?

Hi, I found the command open, then xdg-open ... both do the same, I use Lubuntu, so when I should use one and when should use another?

and how do I use the flag -a for open any web (https://ddg.com for example) using another browser that is NOT my default browser (=Falkon) like Chromium browser? the command is ....

Thank you and Regards!

https://redd.it/1dfm340
@r_bash
Official page

Hey guys, someone be so kind to write me in a reply the official bash page to find the noscripting manual and one or another link you can think of, containing tips on noscripting.

https://redd.it/1dg4awa
@r_bash
POSIX 2024 published: $'...' strings, set -o pipefail, find -0, xargs -0, sed -E, readlink, realpath, and more becoming new standards

# [1003.1-2024 - IEEE/Open Group Standard for Information Technology--Portable Operating System Interface (POSIX) Base Specifications, Issue 8](https://ieeexplore.ieee.org/document/10555529)

Non-paywalled specification should eventually replace the current documentation [here at opengroup.org](https://pubs.opengroup.org/onlinepubs/9699919799/).

[HN thread](https://news.ycombinator.com/item?id=40679809)

Highlights on HN from [a-french-anon](https://news.ycombinator.com/threads?id=a-french-anon):

> * readlink/realpath (https://austingroupbugs.net/view.php?id=1457)
>
> * find -print0, xargs -0 and read -d (https://austingroupbugs.net/view.php?id=243)
>
> * find -iname (https://austingroupbugs.net/view.php?id=1031)
>
> * sed -E (https://austingroupbugs.net/view.php?id=528)
>
> * set -o pipefail (https://austingroupbugs.net/view.php?id=789)

Perhaps not strictly bash-related, but a rising tide lifts all boats.

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