r_bash | Unsorted

Telegram-канал r_bash - r_bash

36

Credits: @r_channels & @reddit2telegram

Subscribe to a channel

r_bash

Mastering Bash: A Cheat Sheet of the Top 25 Commands and Creating Custom Commands
https://www.codelivly.com/mastering-bash-cheat-sheet-of-the-top-25-commands-and-creating-custom-commands/

https://redd.it/11dc8r8
@r_bash

Читать полностью…

r_bash

where did I go wrong here in my code?

I took an assesment for a job through HackerRank and got this one wrong and I cant go back and look at the actual assesment anymore but its "GRINDING MY GEARS" like Peter Griffin that I got this wrong.

Problem Statement:

complete function mort_calc given the loan amount annual interest and period of loan years, you need to calculate the monthly payment. the loan amount is principle. the annual interest can be converted into normal percent interest per month

#!/bin/bash

mortgagecalculator() {
principal=$1
annual
interestrate=$2
years=$3

# Calculate the monthly interest rate
monthly
interestrate=$(echo "scale=8; $principal + $annualinterestrate + $years" | bc -l)

# Return the monthly payment
echo "$monthly
payment"
}

# sample input
principal=300000
annualinterestrate=0.0375
years=30

# call the function
monthlypayment=$(echo "$principal + $annualinterestrate + $years" | bc)

result=$(printf "%.2f" $monthly
payment)

# output
echo $result
# output: 1389.23


this code is not outputting what its supposed to be down there at the bottom, I cant find where my calculations went wrong.

Thanx in advance ya'll

https://redd.it/11db80x
@r_bash

Читать полностью…

r_bash

Explanation of sed Command

I was wondering if someone could explain the following sed command:

sed --in-place '/text1/{n; s/text2/text3/}' file.txt

It's supposed to replace text2 with text3 but only if it is on a line following a line that contains text1. I get the /text1/ portion which is supposed to select lines with text1 in them. What I can't seem to find an explanation for is why curly braces are used and what n; inside those braces does to make this command only act on a line that follows a line containing text1.

https://redd.it/11d1k3v
@r_bash

Читать полностью…

r_bash

An efficient way to get a line-by-line time profile (showing how long each individual command took to execute) for a bash script/function
https://github.com/jkool702/timeprofile/blob/main/setup.bash

https://redd.it/11ctlen
@r_bash

Читать полностью…

r_bash

How can I display a message on terminal in a bash script when the user launches ctrl+c on the gnome-terminal in a way that does not interrupt the bash script execution?

How can I display a message on terminal in a bash script when the user launches ctrl+c on the gnome-terminal in a way that does not interrupt the bash script execution? That means the script should not come to a halt or change the execution flow or results. Except for the message on terminal, it should just run as if no ctrl+c had been used.

Thanks

https://redd.it/11cbjch
@r_bash

Читать полностью…

r_bash

Shellcheck says my code is okay when it isn't

Why does shellcheck say the following is okay,

#!/usr/bin/env bash
for drive in /dev/sata[0-9]{1,2}; do echo "$drive"; done

when it does not work as I expected:

# for drive in /dev/sata[0-9]{1,2}; do echo "$drive"; done
/dev/sata[0-9]1
/dev/sata[0-9]2

I've got it working by using:

#!/usr/bin/env bash
for drive in /dev/sata*; do
if [[ $drive =~ /dev/sata[1-9][0-9]?$ ]]; then
echo "$drive"
fi
done

Which returns the names of my 4 sata drives (and excludes the partitions on each drive):

/dev/sata1
/dev/sata2
/dev/sata3
/dev/sata4

But I'm curious why shellcheck led me down a dead end?

https://redd.it/11c2355
@r_bash

Читать полностью…

r_bash

Create case statement dynamically

I've been trying to put together a function to access and edit gists using the github gh command. I've succeeded in getting the correct format for the case options but just trying to piece it all together is a bit troublesome.

The code snippet is:

paste <(seq $(gh gist list --limit 15 | wc -l); gh gist list --limit 15 | awk '{ print " gh gist edit "$1 " ;;" }') | pr -2 -t -s")"

This outputs code similar to this:

1) gh gist edit XXXXXXXXXXXXXXXXXXXX ;;

2) gh gist edit XXXXXXXXXXXXXXXXXXXX ;;

3) gh gist edit XXXXXXXXXXXXXXXXXXXX ;;

4) gh gist edit XXXXXXXXXXXXXXXXXXXX ;;

5) gh gist edit XXXXXXXXXXXXXXXXXXXX ;;

6) gh gist edit XXXXXXXXXXXXXXXXXXXX ;;

7) gh gist edit XXXXXXXXXXXXXXXXXXXX ;;

8) gh gist edit XXXXXXXXXXXXXXXXXXXX ;;

9) gh gist edit XXXXXXXXXXXXXXXXXXXX ;;

10) gh gist edit XXXXXXXXXXXXXXXXXXXX ;;

11) gh gist edit XXXXXXXXXXXXXXXXXXXX ;;


I have tried to figure out how to basically inject this code into a case statement. I've found a bit of code that seems like it should accomplish what im looking for but I can't figure out how to get it to run correctly.

The current script is:

#!/bin/bash
set -x
paste <(seq $(gh gist list --limit 15 | wc -l); gh gist list --limit 15 | awk '{ print " gh gist edit "$1 " ;; # " $2 }') | pr -2 -t -s")" > .gist.txt
. <( awk -F= 'BEGIN { print "gistlist() {"
print "case \"$choice\" in" }
{ print "$0" }
END { print "esac"
print "}" }' .gist.txt )

clear & paste <(seq $(gh gist list --limit 15 | wc -l); gh gist list --limit 15 | awk '{ print ") gh gist edit "$1 " ;; # " $2 }') | pr -2 -t -s" "
read -p "pick gist to edit: " -r choice
"$gistlist"

What can I change to make this work the right way or what could be a better way to work this. As is It shows up to 15 gists and will change with new gists added/removed. Once we can get that working, I should be able to add the option to use `gh view` and `gh delete` with the selected gist bit one step at a time. Any help is greatly appreciated


* edit

I got a bit closer with:

#!/bin/bash
set -x
paste <(seq $(gh gist list --limit 15 | wc -l); gh gist list --limit 15 | awk '{ print " gh gist edit "$1 " ;; # " $2 }') | pr -2 -t -s")" > .gist.txt
. <( awk -F= 'BEGIN { print "gistlist() {"
print "case \"$choice\" in" }
{ print "$0" }
END { print "esac"
print "}" }' .gist.txt )

# Within your while loop (or wherever else you want):
clear & paste <(seq $(gh gist list --limit 15 | wc -l); gh gist list --limit 15 | awk '{ print ") gh gist edit "$1 " ;; # " $2 }') | pr -2 -t -s" "
read -p "pick gist to edit: " -r choice
#"$gistlist"
paste <(seq $(gh gist list --limit 15 | wc -l); gh gist list --limit 15 | awk '{ print " gh gist edit "$1 " ;; # " $2 }') | pr -2 -t -s")" | awk -F= 'BEGIN { print "case \"$choice\" in" }
{ print $0 }
END { print "esac"}'

https://redd.it/11bpkhv
@r_bash

Читать полностью…

r_bash

I need help with this conditional. For some reason its not working the way is intended.

Please don't belittle me, I feel pretty dumb already.

But this script I wrote is to check all the subdirectories, and check if there is a .rar file, and only extract it if there is not an .mkv, .mp4 or .avi file. The thing is that my conditional always seems to evaluate to true.

The reason for the conditional is so I can run the script again and not to extract again the the rar files if they have already been extracted. However, when I run the script on a folder where there is a .rar file and no .mkv, it exctacts it, but when I run the script again, it will attempt to extract it again even though the condition states not to run the unrar command if one of the other 3 filetypes are already there.

Can someone take a quick look at the code and see what am I doing wrong? Thanks in advance.

#!/bin/bash

# Find all .rar files in the current directory and all
subdirectories
find . -type f -name '.rar' | while read rarfile; do
# Get the directory containing the .rar file
dir=$(dirname "$rarfile")
# Check if a .mp4, .mkv, or .avi file is in the same directory
if ! ls "$dir"/
.mp4 "$dir"/.mkv "$dir"/.avi 1> /dev/null 2>&1; then
# If no .mp4, .mkv, or .avi file is found, extract the .rar file
echo "Extracting $rarfile..."
unrar x "$rarfile" "$dir"
fi
done





Edit: I tried the following changes uding compgen instead and I still get same results.


#!/bin/bash

# Find all .rar files in the current directory and all subdirectories
while read -r rarfile; do
# Get the directory containing the .rar file
dir=$(dirname "$rarfile")
# Check if a .mp4, .mkv, or .avi file is in the same directory
if ! compgen -G "$dir/.{mp4,mkv,avi}" >/dev/null; then
# If no .mp4, .mkv, or .avi file is found, extract the .rar file
echo "Extracting $rarfile..."
unrar x "$rarfile" "$dir"
fi
done < <(find . -type f -name '
.rar')

https://redd.it/11az0u0
@r_bash

Читать полностью…

r_bash

Introduction To Bash Scripting
https://ostechnix.com/introduction-to-bash-scripting/

https://redd.it/11amnxs
@r_bash

Читать полностью…

r_bash

AWK wildcard, is it possible?

I have a file.txt with contents below:

02/23/2023 | 06:56:31 | 1| COM| Q| T| | 02/23/2023 | 07:25:00 | 07:30:00
02/23/2023 | 06:56:31 | 2| Ord Sh| Q| T| | 02/23/2023 | 07:25:00 | 07:30:00
02/22/2023 | 07:10:02 | 3| c.CS| Q| D1| | 02/23/2023 | 00:00:01 | 00:00:01
02/21/2023 | 19:50:02 | 4| p Inc| Q| D2| | 02/23/2023 | 00:00:01 | 00:00:01
02/21/2023 | 19:50:02 | 5| s Cl A | Q| D3| | 02/23/2023 | 00:00:01 | 00:00:01

I would like to search the 6th column for 'D'
Expected result:

02/22/2023 | 07:10:02 | 3| c.CS| Q| D1| | 02/23/2023 | 00:00:01 | 00:00:01
02/21/2023 | 19:50:02 | 4| p Inc| Q| D2| | 02/23/2023 | 00:00:01 | 00:00:01
02/21/2023 | 19:50:02 | 5| s Cl A | Q| D3| | 02/23/2023 | 00:00:01 | 00:00:01

I've tried several variations of the command below, but I just can't figure out the proper way to do the wild card. Is it even possible?


awk -F "|" '$6 == "D"' file.txt

https://redd.it/11abkw5
@r_bash

Читать полностью…

r_bash

API key variable won't work with curl

If I have:

#!/bin/bash

APIKEY="myapikey-123-45"

curl --location '
https://api.website.com/v2/endpoint' \
--header 'X-API-Key: ${API
KEY}' \
--header 'Content-Type: application/json' \
--data '@test.json'

I get:

{"errors":{"Invalid Authentication":"Provided API Key Header Authentication credentials were invalid"}}

But if I have:

#!/bin/bash

curl --location 'https://api.website.com/v2/endpoint' \
--header 'X-API-Key: myapikey-123-45' \
--header 'Content-Type: application/json' \
--data '@test.json'

It works fine. Why? How do I get curl to recognize the API_KEY variable?

https://redd.it/11a1v8r
@r_bash

Читать полностью…

r_bash

spec char on bash

got a version of bash that ignores special chars z(-./) in progs or at bash prompt. ics4 android craig notebook zielmicha android emacs. it's a full gnu emacs except for this. there is a github for it

https://redd.it/119zn06
@r_bash

Читать полностью…

r_bash

I’ve been passed a bash script and have no idea where to start

I’m not looking for someone to explain this, rather point me in the right direction (unless you have time and feeling willing).

I’m no AWS expert and have adopted an EC2 instance which has user data (a bash script) for when the server spins up.

I haven’t a clue what any of it is doing in order to debug. Where do I start?

https://pastebin.com/qeKtkHNq

https://redd.it/11994gn
@r_bash

Читать полностью…

r_bash

Question about incrementing a variable

Hi and thank you for the help!

I am a newbie, sorry for the simple question, but I have to do the script this morning, so I cannot test and try too much.

I need to do a script that assign a number (that start at 5) and increment by 1 at each new user created. Users are also a variable (I have around 500 users to create with the script that also need an assign number).

What would be a good way to define my $NUMBER variable?

Can I do something like that:
$USER
NUMBER=$(i=5; while(($i­>5)) do echo $i((i++)) done)


Thank you again and sorry for the newbie question.. Any help would be greatly appreciated!

https://redd.it/1192vdk
@r_bash

Читать полностью…

r_bash

== \~* ]]; then`
       `eval $1="$(printf ~%q "${!1#\~}")";`
   `fi`
`}`
`__get_cword_at_cursor_by_ref ()`  
`{`  
   `local cword words=();`
   `__reassemble_comp_words_by_ref "$1" words cword;`
   `local i cur="" index=$COMP_POINT lead=${COMP_LINE:0:COMP_POINT};`
   `if [[ $index -gt 0 && ( -n $lead && -n ${lead//[[:space:]]/} ) ]]; then`
       `cur=$COMP_LINE;`
       `for ((i = 0; i <= cword; ++i))`
       `do`
           `while [[ ${#cur} -ge ${#words[i]} && ${cur:0:${#words[i]}} != "${words[i]-}" ]]; do`
               `cur="${cur:1}";`
               `((index > 0)) && ((index--));`
           `done;`
           `if ((i < cword)); then`
               `local old_size=${#cur};`
               `cur="${cur#"${words[i]}"}";`
               `local new_size=${#cur};`
               `((index -= old_size - new_size));`
           `fi;`
       `done;`
       `[[ -n $cur && ! -n ${cur//[[:space:]]/} ]] && cur=;`
       `((index < 0)) && index=0;`
   `fi;`
   `local "$2" "$3" "$4" && _upvars -a${#words[@]} $2 ${words+"${words[@]}"} -v $3 "$cword" -v $4 "${cur:0:index}"`
`}`
`__git_eread ()`  
`{`  
   `test -r "$1" && IFS='`
`' read "$2" < "$1"`
`}`
`__git_ps1 ()`  
`{`  
   `local exit=$?;`
   `local pcmode=no;`
   `local detached=no;`
   `local ps1pc_start='\u@\h:\w ';`
   `local ps1pc_end='\$ ';`
   `local printf_format=' (%s)';`
   `case "$#" in`  
       `2 | 3)`
           `pcmode=yes;`
           `ps1pc_start="$1";`
           `ps1pc_end="$2";`
           `printf_format="${3:-$printf_format}";`
           `PS1="$ps1pc_start$ps1pc_end"`


I've tracked some of it down to [git-prompt.sh](https://git-prompt.sh), which I don't have installed anywhere - yet it's clearly that code. Other parts of the code resemble /usr/share/bash-completion/bash\_completion, which makes me think that perhaps this is all normal!

Is it?

https://redd.it/118u0pu
@r_bash

Читать полностью…

r_bash

help script is not functioning properly

So here's some of the function of my setup script

#!/usr/bin/env bash
# set -x

base_url="https://raw.githubusercontent.com/lime-desu/dootsfile/main"

declare -A PACKAGE_LISTS=(
["pacman"]="${base_url}/scripts/install/packages/arch.txt"
["apt"]="${base_url}/scripts/install/packages/debian.txt"
["dnf"]="${base_url}/scripts/install/packages/fedora.txt"
["xbps-install"]="${base_url}/scripts/install/packages/void.txt"
)

install_packages() {
for package_manager in "${!PACKAGE_LISTS[@]}"; do
case "$package_manager" in
dnf|apt) package_manager_command="sudo $package_manager install ";;
pacman|xbps-install) package_manager_command="sudo $package_manager -S";;
*) echo "${BLD}${RED}Error:${RST} Unsupported package manager.";;
esac
readarray -t packages < <(curl -fsSL "${PACKAGE_LISTS[$package_manager]}")
package_list=$(printf '%s ' "${packages[@]}")

eval "${package_manager_command} ${package_list}"
bat cache --build
done
}

install_packages


What it does is fetch the packages list from the remote url on the defined associative array and install it.

Now at first glance the function is really fine. trying it out Yes it works, it does install all of the packages defined on the list.txt (even though already installed).

I decided to do some testing i removed some packages (uninstalled bat btop cava chafa delta exa and neofetch). Now I run again the script. All of my removed packages doesn't get installed.

Hmm, that's weird there's something wrong, now I did some debugging

+ eval 'sudo dnf install  alacritty bat btop cava chafa util-linux-user curl git-delta exa fd-find foot thefuck fzf git jq kitty lsd mpv neofetch neovim ripgrep stow starship tar tmux unzip wget wl-clipboard zsh '
++ sudo dnf install alacritty bat btop cava chafa util-linux-user curl git-delta exa fd-find foot thefuck fzf git jq kitty lsd mpv neofetch neovim ripgrep stow starship tar tmux unzip wget wl-clipboard zsh
Last metadata expiration check: 1:26:27 ago on Mon 27 Feb 2023 08:07:52 PM PST.
Package alacritty-0.10.1-3.fc37.x86_64 is already installed.
Package util-linux-user-2.38.1-1.fc37.x86_64 is already installed.
Package curl-7.85.0-6.fc37.x86_64 is already installed.
Package foot-1.13.1-1.fc37.x86_64 is already installed.



As you can see on the log the package that I removed are listed clearly (sudo dnf install ... bat btop cava ... git-delta...) and yet why it doesnt get included on the installation any ideas why?

https://redd.it/11dc4fh
@r_bash

Читать полностью…

r_bash

How can i check if a file exists with a certain extension

I need to check if a file exists with a specific extension. Like file.chd specifically. However [ -f $file.chd ] doesn't work for example. There are other files of the same name with a different extension that the -f option picks up instead. How should i do this

https://redd.it/11da7sx
@r_bash

Читать полностью…

r_bash

Simple bash TUI toolkit

Providing a clean bash UI sometimes becomes a mess and interactivity is hard to achieve especially when it should be portable.

So I built a tiny library making it a bit easier:
https://github.com/timo-reymann/bash-tui-toolkit

The target is to provide a simple-to-use toolkit that can be dropped into any bash script and is compatible no matter the target system.

Works fine on Windows, Linux and MacOS so far :)

https://redd.it/11cwsna
@r_bash

Читать полностью…

r_bash

Why is sed not applied to the output in this script?

ssh -T root@somehost << EOL
wget https://somesite | tee -a wget.log | sed '/blah/d'
EOL

https://redd.it/11cmm2p
@r_bash

Читать полностью…

r_bash

How many shell scripts are supporting your app or mission critical services?

You know: those quick and dirty ones you develop to meet a deadline yet they live on and are impossible to remove?

I ask not only out of curiosity but also to offer some solutions.

https://redd.it/11c3ef0
@r_bash

Читать полностью…

r_bash

Why is this only triggering on Saturday and not

This was working on a previous installation of Linux Mint. I have since migrated to MxLinux. So much more lightweight. I transferred some bash scripts over but now it triggers only on Saturdays a 1600. when before it triggered M-F as expected. I removed everything that is not needed below the time checks as it is not necessary. I have checked my date and time on my OS to ensure it is correct.

The actions under the initial time and date check are performing 7 days a week instead of the days of the week of 1-5 also. ZSH is also needed due to needing some to read decimals which bash cannot correctly complete.

&#x200B;

The end of day notify triggers only on Saturday at 1600. I have changed nothing from one OS to another during the migration.

#!/usr/bin/env zsh
export TERM=xterm-256color
eodnotify=15:59
while true ; do
if [ "$(date +"%T")" > '09:30:00' ] && [ "$(date +"%T")" < '16:00:00' ] && [ "$(date +"%u")" -ge 1 ] && [ "$(date +"%u")" -le 5 ]; then
<actions 1>
if <actions 1 check>; then
<actions>
fi
elif [ "$(date +%H:%M)" == *"$eodnotify"* ];then
<actions>
fi
done

https://redd.it/11bw6vg
@r_bash

Читать полностью…

r_bash

What would a script like this look like?

In short, I want a script that, when executed, changes the contents of my clipboard.

&#x200B;

For example, if https://reddit.com/r/bash is copied to the clipboard, I want my script to change it to https://teddit.net/r/bash (in other words, if reddit.com is there, change it).

&#x200B;

I want the same for other websites as well (https://youtube.com/watch?v=dQw4w9WgXcQ becomes https://piped.kavin.rocks/watch?v=dQw4w9WgXcQ)

&#x200B;

&#x200B;

Also, how do you make a script executable just by pressing specific keys?

https://redd.it/11b0n1d
@r_bash

Читать полностью…

r_bash

Show curl progress bar from script within script

If I have in a script:

echo $URL

curl --progress-bar \
-H "X-API-Key: ${APIKEY}" \
-X POST \
--data-binary "$MEDIA
PATH" \
$URL \
| cat

And I run the script, it shows the progress bar.

But if I call on that script with another script:

echo -e "\nUploading to SA...\n"
( . /usr/bin/transfernotify-sauploader.sh )

It will echo the $URL but it won't show the progress bar. How do I get the progress bar to display in the main script (which is a systemd service)?

https://redd.it/11avz2k
@r_bash

Читать полностью…

r_bash

Grep whole word

I've done this before so I don't understand why I'm having such a hard time getting grep to match a whole word and not part of a word.

I'm trying to match /dev/nvme1n1 and not /dev/nvme1n1p1 or /dev/nvme1n1p2 etc.

# num=1
# nvme list | grep -e /dev/nvme${num}
/dev/nvme1n1 22373D800812 WDBLACK SN770 500GB <-- I want only this line
/dev/nvme1n1p1 22373D800812 WD
BLACK SN770 500GB
/dev/nvme1n1p2 22373D800812 WDBLACK SN770 500GB
/dev/nvme1n1p3 22373D800812 WD
BLACK SN770 500GB

I've tried all the regex flavors grep supports trying to get it match /dev/nvme${num}\\b or "/dev/nvme${num} " ending in a space. But nothing works.

None of these return anything:

# nvme list | grep -e '/dev/nvme'$num'\b'
# nvme list | grep -e /dev/nvme$num'\b'
# nvme list | grep -e "/dev/nvme$num\b"
# nvme list | grep -e /dev/nvme$num\\b
# nvme list | grep -G /dev/nvme$num\\b
# nvme list | grep -P /dev/nvme$num\\b
# nvme list | grep -E /dev/nvme$num\\b
# nvme list | grep -e "/dev/nvme${num}\b"
# nvme list | grep -E "/dev/nvme${num}\b"
# nvme list | grep -P "/dev/nvme${num}\b"
# nvme list | grep -G "/dev/nvme${num}\b"
# nvme list | grep -G "/dev/nvme${num} "
# nvme list | grep -P "/dev/nvme${num} "
# nvme list | grep -E "/dev/nvme${num} "
# nvme list | grep -e "/dev/nvme${num} "
# nvme list | grep -w /dev/nvme${num}
# nvme list | grep -w /dev/nvme$num
# nvme list | grep -w nvme$num

What am I missing?

https://redd.it/11aine7
@r_bash

Читать полностью…

r_bash

I F***ed up

I was fixing some stuff in a small cs app and needed to remove './bin', but forgot the '.' and removed /bin. I used sudo, and I have no idea why.

I just snagged /bin from a kali VM. I have no idea what in total is lost. I'll only know when I need to run a command, and I can't run it because it's gone.
I have a custom backup manager and created a backup of my entire $HOME directory because I was ready to reset my OS.

https://preview.redd.it/e048fjiupzja1.png?width=818&amp;format=png&amp;auto=webp&amp;v=enabled&amp;s=760de143c9cb3933d5b50855e6a7aa744a54fe43

I am not anywhere near a pro with bash, so I have no idea if this will have bad long-term effects on my machine.

Will bash be okay even though I've just performed brain surgery on it?

https://redd.it/11a6j07
@r_bash

Читать полностью…

r_bash

Bash scripting tips that can save time on Linux
https://www.codelivly.com/bash-scripting-tips-that-can-save-time-on-linux/

https://redd.it/119z1ci
@r_bash

Читать полностью…

r_bash

Bash vs. Python: For Modern Shell Scripting
https://levelup.gitconnected.com/bash-vs-python-for-modern-shell-scripting-c1d3d79c3622?sk=0a8ea9b2ebc5e413072d26a94f40fbc6

https://redd.it/119x3n6
@r_bash

Читать полностью…

r_bash

Rename files with unique file names

I inherited a filesystem with a rather large number of files in a lot of directories and subdirectories. Most are fine, but it looks like a dozen or so have been “managed” by what I can only guess was a script gone awry.

In some of the directories I have a bunch of unique .pdf files with oddly sequenced file names; specifically, they’re all a series of 1’s followed by the .pdf suffix. For example:

1.pdf
11.pdf
111.pdf
1111.pdf

111111111111111111111111111111111111111.pdf
…and so on.

I managed to not care until I learned that a Java app some folks use that references these files chokes and crashes on the longer file names. Changing the Java app which is older than dirt isn’t likely anytime soon.

My command of regular expressions is very tenuous at best and I’m struggling to find these files and safely rename all of them to short and unique file names while keeping them in their current directories. Bonus if I can keep them in the same listing order because I’m not sure if we care about that.

I’ve dabbled with for loops and the rename or mv command but I’m not smart enough to not do damage.

https://redd.it/119812p
@r_bash

Читать полностью…

r_bash

Hello guys newbie question related to grep here

Hello guys I have a text that is all in the English alphabet except two words which are in Cyrillic alphabet, so how do I get an output on only these two words with grep what I'm doing so far egrep '[A-Za-z0-9\]|\\W' when i add -v nothing in output. Thanks in advance

https://redd.it/118v1uu
@r_bash

Читать полностью…

r_bash

ubuntu 20, 22, pi: /sh/bash:- should my 'set' display 1,000 lines of script along with the variables already set?

I don't know if this is normal, but I would have thought that I could display all existing variables via the $set command. And it does. But it also shows hundreds of lines of what appears to be script code, along with other lines. I've checked on multiple systems here and they all have it, so perhaps it's normal. But it's possible that I've modified my .bashrc or python env or other system that's called in the .bashrc, and accidentally had it read in some huge amount of irrelevant bash shell code or something. Below are some excepts. If this is normal, great, otherwise if it isn't could someone just tell me it's fux0red and I'll go and figure out the rest. I just don't want to invest a couple of hours only to find that this is normal! \[edit: too late. I just spent 2 hours checking before posting this so I don't look like an idiot. Didn't help.\]

`$set`

`BASH=/bin/bash`
`BASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:globasciiranges:globskipdots:histappend:interactive_comments:patsub_replacement:progcomp:promptvars:sourcepath`
`BASH_ALIASES=()`
`BASH_ARGC=([0]="0")`
`BASH_ARGV=()`
`BASH_CMDS=()`
`BASH_COMPLETION_VERSINFO=([0]="2" [1]="11")`
`BASH_LINENO=()`
`BASH_LOADABLES_PATH=/usr/local/lib/bash:/usr/lib/bash:/opt/local/lib/bash:/usr/pkg/lib/bash:/opt/pkg/lib/bash:.`
`BASH_SOURCE=()`
`BASH_VERSINFO=([0]="5" [1]="2" [2]="2" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu")`
`BASH_VERSION='5.2.2(1)-release'`
`COLORFGBG='15;0'`
`COLORTERM=truecolor`
`COLUMNS=198`
`DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus`
`DEBUGINFOD_URLS=https://debuginfod.ubuntu.com`
`DESKTOP_SESSION=plasmawayland`


... continues on for a while, then

`XDG_SESSION_TYPE=wayland`
`XDG_VTNR=2`
`XKB_DEFAULT_LAYOUT=us`
`XKB_DEFAULT_MODEL=pc105`
`_=pi`
`__git_printf_supports_v=yes`
`_backup_glob='@(#*#|*@(~|.@(bak|orig|rej|swp|dpkg*|rpm@(orig|new|save))))'`
`_xspecs=([tex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [freeamp]="!*.@(mp3|og[ag]|pls|m3u)" [gqmpeg]="!*.@(mp3|og[ag]|pls|m3u)" [texi2html]="!*.texi*" [hbpp]="!*.@([Pp][Rr][Gg]|[Cc][Ll][Pp])" [lowrite`
`r]="!*.@(sxw|stw|sxg|sgl|doc?([mx])|dot?([mx])|rtf|txt|htm|html|?(f)odt|ott|odm|pdf)" [rpm2cpio]="!*.[rs]pm" [localc]="!*.@(sxc|stc|xls?([bmx])|xlw|xlt?([mx])|[ct]sv|?(f)ods|ots)" [hbrun]="!*.[Hh][R`
`r][Bb]" [vi]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [latex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [view]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp`
`?(e)g|avi|asf|ogg|class)" [madplay]="!*.mp3" [compress]="*.Z" [pdfjadetex]="!*.@(?(la)tex|texi|dtx|ins|ltx|dbj)" [pbunzip2]="!*.?(t)bz?(2)" [lrunzip]="!*.lrz" [gunzip]="!*.@(Z|[gGd]z|t[ag]z)" [oowri`
`ter]="!*.@(sxw|stw|sxg|sgl|doc?([mx])|dot?([mx])|rtf|txt|htm|html|?(f)odt|ott|odm|pdf)" [epiphany]="!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))" [acroread]="!*.[pf]df" [znew]="*.Z" [kwrite]="*.@([ao]|so|s`
`o.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [xemacs]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [gview]="*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gi`


(this last one goes on for \~900 characters), then there's the start of a few hundred lines of script:

`CompWordsContainsArray ()`  
`{`  
   `declare -a localArray;`
   `localArray=("$@");`
   `local findme;`
   `for findme in "${localArray[@]}";`
   `do`
       `if ElementNotInCompWords "$findme"; then`
           `return 1;`
       `fi;`
   `done;`
   `return 0`
`}`
`ElementNotInCompWords ()`  
`{`  
   `local findme="$1";`
   `local element;`
   `for element in "${COMP_WORDS[@]}";`
   `do`
       `if [[ "$findme" = "$element" ]]; then`
           `return 1;`
       `fi;`
   `done;`
   `return 0`
`}`
`__expand_tilde_by_ref ()`  
`{`  
   `if [[ ${!1-}

Читать полностью…
Subscribe to a channel