r_bash – Telegram
How to add an input that is actually multiple hexadecimal elements

I have an input like this
“30 0A 0F” that is enter into the command line

I’m not sure how to loop through and add these numbers. I have tried using printf but I don’t have a decimal to hex conversion. I need these strings to individually be casted hexadecimal as is.

How can I do this?

https://redd.it/117gs0u
@r_bash
How to edit my git command to output requested data using string separator?

Using git I'm getting a list of all large files in a repo. The command looks scary but it's really just pulling data and then doing some data engineering.

git rev-list --objects --all |
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' %(id)' |
sed -n 's/^blob //p' |
sort --numeric-sort --key=2 |
gcut -c 1-12,41- |
$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest

Here is an example output of what the noscript above pumps out:
ne3ee2e43e12 1.0MiB path/to/large/files.png ID

I would like to use a semi-colon as a delimiter between each datapoint called in the command. So the expected output would be like this:

ne3ee2e43e1x; 1.0MiB; path/to/large/files.png; ID


I can do so like this:

git rev-list --objects --all |git cat-file --batch-check='%(objectname);%(objecttype);'

Adding semi-colons in between each git object. But for some reason when I combine everything together, the noscript does not work?

How can I fix my noscript below to get it working and add semi-colon separators for my --batch-check param?

git rev-list --objects --all | git cat-file --batch-check='%(objecttype);%(objectname);%(objectsize);%(rest)' | sed -n 's/^blob //p' | awk '$2 >= 2^20' | sort --numeric-sort --key=2 | gcut -c 1-12,41- |$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=1 --round=nearest

https://redd.it/117li9u
@r_bash
Script cannot use text file given as command line arguments

Practicing some basic bash to prepare for a new job. I am using a cygwin terminal on windows 10.

I am trying to output the text from a file (numbers.txt in my cwd) which I am entering as parameter with this line.

​

cat $1

​

I keep getting this error

​

cat: 'numbers.txt'$'\\r': No such file or directory

​

What am I doing wrong?

https://redd.it/117mqzt
@r_bash
how do I use/save bash files on windows and execute?

i tried looking it up but i either see download extension for my code editor which hasnt worked or use linux which i can't rn. is there something im missing?
Edit: solved
I used vs code and ctrl + shift +p then selected default profile and chose bash which let me execute the bash file

https://redd.it/117mdtv
@r_bash
decrypt a file in bash

i have a scrip that i am looking to automate so as to have it run once a month. my issue is that this bash noscript reads the password file but cannot come up with a way to secure that password file so its not in plain text. any idea how i can encrypt and decrypt that password file and decrypt it using the noscript and still keep it secured? decryption inside the noscript is not working as its simply leaving the key under the door

https://redd.it/117xgr0
@r_bash
Hello guys how can I revert regex

cat misc.txt | egrep '[[:digit:\]\]{1,2}-[A-Za-z\]{3}-[[:digit:\]\]{4}'

on 18-Jun-1815 outside Brussels, Belgium lasted a whole day and

The American George B. Selden filed for a patent on 8-May-1879.

​

Hello guys I have problem reversing the dates in a format where the year is first like 1815-jun-18 without using date any help will be much appreciated

https://redd.it/117yz67
@r_bash
Headphone indicator bash noscript help

Script suppose to show an headphone icon when the headphone is contented, and remove it when the headphone jack is removed.

the problem is with the pid and kill pid, I can remove the icon from the terminal using pidof and kill commands but it doesn't work from the noscript.

#!/bin/bash
FLAG=1
while true; do
HEADPHONE=$(amixer -c 0 contents | awk -F "=" 'FNR == 3 {print $2}')
if [ "$HEADPHONE" = "on" && $FLAG -eq 1 ]; then
yad --notification --image="/home/oren/Documents/headphone.png"
PID=$(pidof yad |awk '{print $1}')
FLAG=0
echo "$(date) on flag $FLAG PID $PID" >> "/home/oren/Documents/headphone.log"
fi
if [ "$HEADPHONE" = "off" && $FLAG -eq 0 ]; then
kill '$PID'
FLAG=1
echo "$(date) off flag $FLAG PID $PID" >> "/home/oren/Documents/headphone.log"
fi
sleep 1
done

https://redd.it/1183pvy
@r_bash
Systemd in a Debian container on ChromeOs accepts bash

Yup, as long as your noscripts executed by a systemd service starts with a bash shebang, things are good. Arrays, and [[ \]\] and other stuff works totally fine.

Even if the documentation states that the noscripts must be sh compatible.

https://redd.it/118fy6j
@r_bash
Ctrl + Meta(Windows) + Right/Left - How come it isn't well known?

So I've accidentaly (I have ctrl + alt + left/right bound as home/end) discovered that ctrl + meta + left/right in bash jumps the cursor between words/commands/arguments/whatever, separated by any non-alphanumerical sign, like whitespaces, slashes, underscores, so for example instead of manually replacing file name in a long path I can easily jump to the last slash and use alt+d to remove the filename and type another.

Why I haven't seen this anywhere in 20 years of using linux? I couldn't find any docs using Google either, and it is soooo useful.

https://redd.it/118jmc6
@r_bash
I need some bash help

I need to convert all my ps1 games to chd files (type of compressed data) and I'm having trouble with part of automating it. What i need to do is used sed to get the file names (or if there is a way to strip extensions then use that) and then for everyone one of those files extract it, go into the folder created run chdman, copy the .chd file back to the main directory with the same name then move on to the next one. How can i run that for every file named that. I could probably do it with the find command and not need to do it through bash but I'd like a file to run that would do this

https://redd.it/118mjtg
@r_bash
What is a good way to learn bash noscripting

So I'm comfortable using bash at the commandline but i know little about noscripting with it. What are some good ways to learn and practice with it

https://redd.it/118nry1
@r_bash
Import select fields from one XML into another?

I have two copies of an XML file. The file is a database for a media library with e.g. name, denoscription, play count, etc.

One copy is "dirty," it's got errors in it, entries for items that don't exist in the library, etc. But it has the play count data that I want to preserve.

The other copy is "clean," it has all the errors corrected and the missing entries removed...but it's missing the play count.

What I want to do is, for each entry in the "clean" list, if that entry exists in the "dirty" list (it always should) and if that dirty entry has a <playcount> field (it might or might not), then import that field from the "dirty" list into the "clean" list.

This feels simple and difficult at the same time. I'm not well versed in XML manipulation. Is this something we can do? I have access to xmlstarlet, or other tools available on raspberry pi legacy (arm Linux/Debian 10.)

https://redd.it/118pi26
@r_bash
ubuntu 20, 22, pi: /sh/bash:- should my 'set' display 1,000 lines of noscript 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 noscript 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 noscript:

`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-}
== \~* ]]; 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
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
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 noscript this morning, so I cannot test and try too much.

I need to do a noscript 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 noscript 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
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 noscript 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
I’ve been passed a bash noscript 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 noscript) 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
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