r_bash | Unsorted

Telegram-канал r_bash - r_bash

36

Credits: @r_channels & @reddit2telegram

Subscribe to a channel

r_bash

division of numbers

I am trying to make a notification for low battery for my arch laptop. I decided to use bash because it blends nicely with everything else

#!/bin/bash
chargeNow=$(cat /sys/class/powersupply/BAT0/chargenow)
chargeFull=$(cat /sys/class/powersupply/BAT0/chargefull)

echo $chargeNow
echo $chargeFull

perBat=$((chargeNow/chargeFull))

echo $perBat

as to my knowledge this should output a proper percentage but it outputs 0.

The outputs for chargeNow and chargeFull are correct

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

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

r_bash

bash script development

what would be the overall title of a role that mostly consisted of bash script development. would that be a software developer? or something else?

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

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

r_bash

How do I keep pv printing on the same line of rsync progression instead of scrolling the entire progression? I can't get zenity or yad to show any progress at all.

Thats basically it, I have a script that I use for drive/directory syncing to select a host and then select one or more peripherals in the /media directory to sync to. It's all done and like I want with one exception, I am tying to figure out how to show the progression with a progress bar of some kind that actually show the progress. The pv option works well for the information I need, except it scrolls to the next line on every write instead of overwriting the same line and that's not going to work. I'm not married to pv so if anyone has any better ideas or suggestions...

I was thinking of piping the pv command to a function that forces it to read and rewrite it to the same line by sending it through a printf command, but is there a better way to make pv write to the same line?

Or, is there another way I can do a progress bar when using rsync that will allow me to show a more accurate representation of the syncing process? So far nothing I've tried works to show the progression of rsync. I think the problem is a reliable count progression and the progress bar like with yad and zenity isn't getting the count as it progresses to show the bar sliding across.

Any ideas?

Rsync on a dry run reports 20,000+ files but during the actual write, only those needing updated in the archive on the actual run will update even though both use the same flags and options, throwing off the progress count.

I'm not sure if any of these would make a difference on how rsync passes data to one of the progress options. The "--info=name0" option, I found out, only displays the output line of rsync which would give the status line only of rsync which can work if I can't get an accurate display of a progress bar to work. Should I add a "-v" option as well? Or any other?

The options info sent to both the dry run and actual is:
>OPTIONS="-Puham"

>FLAGS="--no-i-r --info=progress2 --mkpath --preallocate --no-motd"

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

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

r_bash

`fg` does not work in scripts for raw terminal mode processes

just so we are on the same page, here is small c program

void enableRawMode() {
struct termios raw ;
tcgetattr(STDIN_FILENO, &raw);
raw.c_lflag &= ~(ECHO | ICANON | ISIG);
tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
}
int main() {
enableRawMode();
sleep(3)
return 0;

}

to accurately get pid, we do this:

./main & MAIN_PID=$!
echo $MAIN_PID
fg

for some reason this works when copy-pasting this into terminal, but when written in script, running it gets "`tcgetattr: Inappropriate ioctl for device`"

same with when running other programs which use raw mode, like vim (although different error message)

plz help >:

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

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

r_bash

I have a lot of folder in my linux machine with a lot of file, find duplicate files and delete them

I have liinux box and I have many many folders and in each folder many many files.

I am sure many of these files are duplicate, for example I have 1.mp4 in folder Videos, in folder Downloads and other folders.

I want bash script search all hard drive and find these files and show me and after that delete all of them.

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

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

r_bash

I'm trying to make a script to enable/disable a gnome extension

Here is my script :

!/bin/bash

set -x

STATE="$(gnome-extensions show | grep State)"

if [[ $STATE == *"ENABLED"* \]\]; then

gnome-extensions disable

else

gnome-extensions enable

fi

but it succeeds only in enabling the extension and not disabling it, but I can't find what's wrong...
Do you have a clue ? 🎺

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

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

r_bash

am stuck in a gameshell (part 2) btw i cant use if while ... and cant use && ; .... and thx for the help



Objective

Bathilde has received several ASCII puzzles for her party. An ASCII puzzle consists of multiple pieces, where each piece contains a line of ASCII art.

Unfortunately, a sprite has decided to mix up the pieces of all her puzzles. Help Bathilde find the pieces of her favorite puzzle and complete it.

The pieces of her favorite puzzle are located in the files in the "art" directory with a filename:

that starts with the letter "m"
where the 2nd character is an even number
where the 3rd character is an odd number
where the 4th character is the letter "n"
where the 5th character is random
where the 6th character is a question mark "?"
and which ends with a backslash ""

Each piece contains a line in the format:

mathematicaCopy code

N TEXT

where "TEXT" is the N-th line of the puzzle. To complete the puzzle, simply put the pieces in the correct order. For example, if the pieces are:

Copy code

2 | | 1 +-+ 3 +-+

the completed puzzle will be:

Copy code

1 +-+ 2 | | 3 +-+

Once you have completed the puzzle, save the result in the file "ct".

Constraints

You are allowed only "one command" and "zero or one redirection".

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

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

r_bash

am playing a gameshel and got stuck here

You are tasked with controlling the pneumatic tube system used by the Mail Service of the Pierre-Dansereau Science Complex. The system connects three pavilions of the complex as follows:

​

E --->--- PK --->--- SB --->--- CO

\---> transport direction --->

​

This diagram indicates that all cylindrical shuttles transported by the system are inserted at the entrance E and first pass through PK. Those that do not stop at PK continue to SB, and those that do not stop at SB are subsequently routed to CO.

​

The command "depart" inserts shuttles into the system at entrance E. In particular, it generates a sequence of lines in the format:

​

CP message

​

where "CP" is a postal code written on the inserted shuttle and "message" is a string of lowercase letters that form the content of the shuttle. The postal code is a capital letter with the following meaning:

​

the shuttle stops at PK if the postal code is the letter "P",

the shuttle stops at SB if the postal code is the letter "S",

the shuttle stops at CO otherwise.

​

To control the system, you must produce:

​

a "pk" manifest that contains shuttles reaching PK,

an "sb" manifest that contains shuttles reaching SB,

a "co" manifest that contains shuttles reaching CO.

​

For example, if the output of "depart" is:

​

X bonjour

P il neige

S adieu

P il pleut

​

then the "pk" file will contain:

X bonjour

P il neige

S adieu

P il pleut

​

the "sb" file will contain:

X bonjour

S adieu

​

and the "co" file will contain:

X bonjour

​

Constraints

​

You are allowed "one command line" for this task.

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

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

r_bash

Pass output of python/js file as data when using curl

I have been trying to use curl for a post request but the data I am trying to use is from another script file (say output of js or python file).

Something like this :

curl -X POST -H "Content-Type: application/json" -d '$(python test_data.py)' http://localhost:4000/curl-check

in the data section I want to send the json dump from python file, is this possible ?


Thanks.

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

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

r_bash

How many disk reads are too much?

Hello, I designed a daemon that has to periodically retrieve a bit of information from disk, and I want it to be as realtime as possible, but that would imply may be too often hard disk read operations.

An alternative to file read could also be an xattrs read.

What time lapse is sane for a read operation or a read xattrs operation?

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

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

r_bash

# split directories up into nesting levels relative to base search directory
# is base search directory is '/a/b'; then: level 0 is '/a/b', level 1 is '/a/b/_', level 2 is '/a/b/_/_, level 3 is '/a/b/_/_/_' etc.)'
eLevels[0]="${bdir}";
for nn in "${edir[@]%%+([\/\*])}"; do
b="${nn#"${bdir%/}/"}/";
a="${bdir%/}/";
kk=1;
until [[ -z $b ]] || [[ "$a" == "$nn" ]]; do
a+="${b%%/*}/";
b="${b#*/}";
eLevels[$kk]+="${a%\/}"$'\n';
((kk++));
done;
done;

# construct minimal list of files/directories to search that doesnt contain excluded directories and save in array F
# EXAMPLE:
# if the base search directory is '/a/b' and you want to exclude 'a/b/c', 'a/b/d/e', and 'a/b/d/f', this includes:
# everything immediately under '/a/b' except for '/a/b/c' and '/a/b/d' --AND--
# everything immediately under '/a/b/d', except for '/a/b/d/e' and '/a/b/d/f'
mapfile -t F < <(for ((kk=1; kk<${#eLevels[@]}; kk++ )); do
mapfile -t A < <(printf '%s' "${eLevels[$(( $kk - 1 ))]}" | sort -u)
A=("${A[@]}");
for nn in "${A[@]}"; do
mapfile -t B < <(printf '%s' "${eLevels[$kk]}" | grep -F "${nn}" | sort -u)
B=("${B[@]}");

[[ -n "$(printf '%s' "${B[@]//[ \t]/}")" ]] && source /proc/self/fd/0 <<< "find \"${nn}\" -maxdepth 1 -mindepth 1 $(printf '! -path "%s" ' "${B[@]}"; printf '! -wholename "%s/*" ' "${B[@]}")";
done;
done);

# run `find -O3` on the dir list saved in array F, with excluded files (from command line) now being excluded
source /proc/self/fd/0 <<<"find -O3 \"\${F[@]}\" $(printf '! -path "%s" ' "${efile[@]}")";
}

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

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

r_bash

A Bash script thatspurpose is to source the latest release version number of a GitHub repository

To use it set the variable url (or name it whatever)

repo example 1
url=https://github.com/rust-lang/rust.git
repo example 2
url=https://github.com/llvm/llvm-project.git

And run this command in your bash script

curl -sH "Content-Type: text/plain" "https://raw.githubusercontent.com/slyfox1186/script-repo/main/Bash/Misc/source-git-version.sh" | bash -s "$url"

These examples should return the following version numbers for llvm and rust respectively...

17.0.6

1.75.0

It works for all the repos I have tested so far but I'm sure one will throw an error.

If a repo doesn't work let me know and I'll see if I can fix it.

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

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

r_bash

bash script developer

Hi I am a researcher and I have to write some bash scripts for my project but I am too new here. Could you please help me (as a consultant or paid bash script writer)?

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

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

r_bash

BEE-GENTLE-1ST-BASH-SCRIPT

so, I am looking to make my life a bit simple, I use nmap and use some pentesting labs. IP of target always changes and instead of remembering the ip of the target, it would be nice to just use TARGET in my commands that I pass.

I sudo this file and it was giving me ability to append a new targetname and ip to /etc/hosts file
e.g. target1 10.10.10.101

I tried it and it worked, so I added in a command where I need some guidance, pointers on how I can add the delete option. I googled and saw sed command but not sure how to incorporate it.

My expectation is to cat the /etc/hosts file and see whats there, then add or delete as needed before a new pentest box is being worked on.

filename: addtarget.sh
#!/bin/sh
echo "What is the TARGET # please"
read TARGET
echo "Enter IP address please"
read IP
/new line added to delete/ echo "Enter TARGET # to delete from /etc/hosts"
/new line added to delete/ read DEL
/new line added to delete/ sed -i.bak '/target$DEL\'./d' /etc/hosts # will delete lines containing "target."

echo "Adding $TARGET and its associated $IP address for you"
echo "$TARGET $IP" >> /etc/hosts

++++++++++++++++++++++
Thank you in advance to this community and any support you can provide me.

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

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

r_bash

Monitor filesystem events using inotify-tools

# inotify-tools
This is a basic guide to use inotify-tools.

```bash
apt-get install inotify-tools
```

## Initial Command
This is basic command of inotify-tools.

* `inotifywait` is a part of inotify-tools.
* `-m` monitor for events continuously (don't exit after the first event).
* `-e create` watch for file creation events specifically.
* `/path/to/directory` The directory to monitor.
```bash
inotifywait -m -e create /path/to/directory
```

When a new file is created, inotifywait will print a line like -
```
CREATE /path/to/directory/new_file.txt
```
Capture this output in a script or command to perform actions on the new file.

## Using while loop
```bash
inotifywait -m -e create /path/to/directory | while read line; do
# Extract the filename from the output
filename=$(echo $line | cut -d' ' -f3)
# Do something with the new file
echo "New file created: $filename"
done
```

## Additional options
* `-r` Monitor recursively for changes in subdirectories as well.
* `--format %f` Print only the filename in the output.
* `--timefmt %Y%m%d%H%M%S` Specify a custom timestamp format.

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

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

r_bash

How to sort arrays natively in Bash

https://vorakl.com/articles/bash-sort/

Bash supports sorting arrays natively through the asort built-in command. However, this command is not always loaded by default. The article shows how to build Bash from source to access all loadable modules, including asort.

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

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

r_bash

am stuck in a gameshell (part 3) btw i cant use if while ... and cant use && ; .... and thank u guys sm for the help

,------------------------------------------------------------------------.

(_\\ \\

| Objective |

| ========= |

| |

| You are on a road trip and stopped at a gas station to buy a |

| map of Canada. On the back of this map, there is a set of |

| tables that give the city located at each highway exit as well as |

| some of its attractions. We have reproduced these tables in the |

| files in the "tableaux" directory. The file names correspond to the |

| names of highways. They are classified by province in subdirectories |

| of "tableau". Each file presents its data in the following format: |

| |

| - The first line describes the first exit, the second line the |

| second exit, and so on. |

| - The city and its attractions are separated by a semicolon ";" |

| - Attractions are separated by spaces. |

| |

| For example, the Ontario highway 416 is described by the file |

| "tableaux/Ontario/416" which has the content |

| |

| Johnstown;bridge |

| Edwardsburgh;mill gallery |

| Spencerville;sailboat |

| ... |

| |

| indicating that Edwardsburgh is located at the second exit and its |

| attractions are a mill and a gallery. |

| |

| There is exactly one city in Canada that has an "orchestra" and is |

| adjacent to a city with a "mill" on the same highway. Find this |

| city, its highway, and exit number. |

| |

| Constraints |

| =========== |

| |

| - You are allowed only one command. |

| |

| Hints |

| ======= |

| |

| - Try to minimize the number of different commands used. |

_| |

(_/__________________________________________________________________(*)___/

\\\\

))

\^

&#x200B;

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

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

r_bash

Syntax of current branch in terminal is off, please help!

I reformatted my laptop with Linux Mint 21.3, it's coming from 21.2. I commented out this code:

if "$color_prompt" = yes ; then
PS1='${debianchroot:+($debianchroot)}[\03301;32m\\u@\h[\03300m\:[\03301;34m\\w[\03300m\\$ '
else
PS1='${debianchroot:+($debianchroot)}\u@\h:\w\$ '
fi
unset colorprompt forcecolorprompt

and added this code snipped immediately ahead of it:

git
branch() {
git branch 2> /dev/null | sed -e '/^^*/d' -e 's/ \(.\)/(\1)/'
}
if "$color_prompt" = yes ; then
PS1='${debianchroot:+($debianchroot)}[\03301;32m\\u@\h[\03300m\:[\03301;34m\\w[\03301;35m\$(gitbranch)\[\033[00m\]\$ '
else
PS1='${debian
chroot:+($debianchroot)}\u@\h:\w$(gitbranch)\$ '
fi

This resulted in the terminal prompt looking like this:

(bash) user@Grell:~/GitHub/scripts main$

I changed it slightly to:

git_branch() {
git branch 2> /dev/null | sed -e '/^[^
]/d' -e 's/ \(._\)/(\1)/'
}
if "$color_prompt" = yes ; then
PS1='${debianchroot:+($debianchroot)}[\03301;32m\\u@\h[\03300m\:[\03301;34m\\w[\03301;35m\$(gitbranch)\[\033[00m\]\$ '
else
PS1='${debian
chroot:+($debianchroot)}\u@\h:\w$(gitbranch)\$ '
fi

And it looks like this:

(bash) user@Grell:~/GitHub/scripts(m)ain$

Most of the resources I'm finding online provide one of these two code snippets, or something similar, so I haven't yet found a solution. The coloring of the prompt is as it was on my 21.2 installation, so that part's likely correct, I just need to figure out the parentheses.

How can I get it to look like this:

(bash) user@Grell:~/GitHub/scripts(main)$

My entire .bashrc is in comments.

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

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

r_bash

PS1 issues,

My prompt glitches sometimes when scrolling through history, it will do things like drop characters,

"$ git push" will become "$ it push" but still work.

Another one that appears sometimes is ❌ ✔️ will add another of themselves for each character that I delete from my command.

Any ideas what is causeings this?

\------ a the majority (but not all) of my prompt code ------

PS1="\\n${PS1_USER}\\u ${PS1_BG_TEXT}at${PS1_SYSTEM} \\h ${PS1_BG_TEXT}in${PS1_PWD} \\w ${PS1_GIT}\\${GIT_INFO}\\

\\n\\${EXIT_STAT}${PS1_WHITE}\\$ ${PS1_RESET}"

\# function to set PS1

function _bash_prompt(){

\# This check has to be the first thing in the function or the $? will check the last command

\# in the script not the command prompt command

\# sets a command exit statues

if [[ $? -eq 0 \]\]; then

EXIT_STAT="✔️" # Green "✔️" for success

else

EXIT_STAT="❌" # Red "❌" for failure

fi

\# git info

export GIT_INFO=$(git branch &>/dev/null && echo "$(__git_ps1 '%s')")

}


(Edit grammar and formatting)

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

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

r_bash

I'm trying to make a script to enable/disable a gnome extension

Here is my script :

#!/bin/bash

STATE="$(gnome-extensions show **window-list@gnome-shell-extensions.gcampax.github.com** | grep State)"

if [[ $STATE == *"ENABLED"* \]\]; then
gnome-extensions disable **window-list@gnome-shell-extensions.gcampax.github.com**
else
gnome-extensions enable **window-list@gnome-shell-extensions.gcampax.github.com**
fi

but it succeeds only in enabling the extension and not disabling it, but I can't find what's wrong...
Do you have a clue ? 🎺


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

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

r_bash

Commands executed in a subshell meaning?

My understanding of what a subshell is comes from

https://www.gnu.org/software/bash/manual/bash.html#Command-Execution-Environment

which says that “a subshell is a copy of the shell process,” and that “commands are invoked in a subshell environment that is a duplicate of the shell environment…”

This implies that a subshell looks exactly like the parent shell aside from some minor differences which is different from creating a new shell since the new shell won’t see the previous shell’s shell variables.

So for example a bash script is not run in a subshell since it creates a new shell.

Assuming my understanding of what a sub shell is is correct, my confusion stems from

https://www.gnu.org/software/bash/manual/bash.html#Pipelines which says that

“each command in a multi-command pipeline, where pipes are created, is executed in its own subshell, which is a separate process.”


Is a new subshell created for every command “invoked in a subshell environment,” or does it work where builtins or other bash stuff cause a subshell to be created, but a subshell is not created for simple commands and they are the same as running a simple command from the parent shell?


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

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

r_bash

What boredom does to a man | replicating the old TVs 'no signal' color bars in BASH
https://redd.it/1av6c7b
@r_bash

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

r_bash

50 useful scripts you use as a devops?

I know putting json keys to lowerCase and ordering them by alphabetical order is a useful script, but not necessarily for devops, but I am trying to make a list of useful scripts I might have to use at work.

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

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

r_bash

Script update announce: apt-undo

Hey guys. Over two years ago I published the apt-undo bash script on github and announced it in this sub. Recently I overhauled it and implemented some features it lacked. I guess you'll like the brand new -t option.

&#x200B;

Notice: examples in the README are reproducible now.

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

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

r_bash

hacky interactive error handler with restarts for bash
https://github.com/sczi/bash_error_handler

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

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

r_bash

finding files and [sub]directories with exclusions

So, I recently discovered while using `find` and trying to exclude a particular directory via something like

find "${base_dir}" ! -path "${exclude_dir}" ! -wholename "${exclude_dir}/*"

that `find` still scans the excluded directory and then removes them from the output. i.e., it doesnt "skip" this directory, it scans it like all the rest and then removes any results that match the `! -path` or `! -wholename` rule.

This can be a bit annoying (and make the `find` run *really* slow) if the directory you are excluding is, for example:

* the mount point of a huge mounted zfs raidz2 pool storing some 40 TB of data
* the mount point of a 5 tb usb attached HDD to an embedded system that can only read it at a maximum of ~20 MB/s

Being that I ran into both of these in the last few days, In wrote up a little function to exclude directories from find without having to scan through them. That said, its decently robust but Im sure some edge cases will give it trouble, and I feel there is probably a tool that does this more robustly, so if anyone knows what it is by all means let me know.

The function below works by figuring out a minimal file/directory list that is searched (with `find`) that covers everything under the base search dir except the excluded stuff. For example: if you wanted to list everything under `/a/b` except for `a/b/c`, `a/b/d/e`, `a/b/d/f`, and any subdirectories under those three exclusions, this list of "files and directories to search" would include:

* everything immediately under `/a/b` except for `/a/b/c` and `/a/b/d` \-\-AND\-\-
* everything immediately under `/a/b/d`, except for `/a/b/d/e` and `/a/b/d/f`

This function constructs this list by breaking apart excluded directories into "nesting levels" relative to the base search dir and then on each doing `find -mindepth 1 -maxdepth 1 ! -path ...` in a loop on each unique dir from each nesting level.

***

OK, heres the code:

efind () {
## find files/directories under a base search directory with certain files and directories(+sub-directories) excluded
#
# IMPORTANT NOTE:
# excluded directories are not queried at all, making it fast in cases where the excluded directory contains A LOT of data
# (unlike `find "$base_dir" ! -path "$exclude_dir/*"`, which traverses the excluded directory and then drops the results)
#
# USAGE:
# 1st input is the base search directory that you are searching for things under
# All remaining inputs are excluded files and/or directories
#
# dependencies: `realpath` and `find`

local -a eLevels edir efile A B F;
local bdir a b nn;
local -i kk;

shopt -s extglob;

# get base search directory
bdir="${1%\/}";
shift 1;
[[ "${bdir}" == \/* ]] || bdir="$(realpath "${bdir}")";

# parse additional inputs. Split valid ones into seperate lists of files / directories to exclude
for nn in "${@%/}"; do

# get real paths. If path is relative (doesnt start with / or ./ or ~/) assume it is relative to the base search directory (NOT PWD)
case "${nn:0:1}" in
[\~\.\/])
nn="$(realpath "$nn")";
;;
*)
nn="$(realpath "${bdir}/${nn}")";
;;
esac

# ensure path is under base search directory
[[ "$nn" == "${bdir}"\/* ]] || {
printf 'WARNING: "%s" not under base search dir ("%s")\n ignoring "%s"\n\n' "$nn" "${bdir}" "$nn";
continue;
}

# split into files list or directories list
if [[ -f "$nn" ]]; then
efile+=("$nn");
elif [[ -d "$nn" ]]; then
edir+=("$nn");
else
printf 'WARNING: "%s" not found as file or dir.\n Could be a "lack of permissions" issue?\n ignoring "%s"\n\n' "$nn" "$nn";
fi;

done;

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

r_bash

Iterating over ls output is fragile. Use globs.

My editor gave me this warning, can y'all help me understand why?

The warnig again is:

`Iterating over ls output is fragile. Use globs.`

Here is my lil script:

#!/usr/bin/env bash
for ZIPFILE in $(ls *.zip)
do
echo "Unzipping $ZIPFILE..."
unzip -o "$ZIPFILE"
done

What should I use instead of `$(ls *.zip)` and why?

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

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

r_bash

Utility that Scans A Bash Script And Lists All Required Commands

#### I'm looking for a utility that scans a bash script and lists all required commands. Some reqs and specs, v00.03.

Do you know of such a beast?

I have not been able to frame a valid web query, other than ones that generate terabytes of cruft.

Barring that, I could use some help with specs.

**Shortcuts?**

* I can safely ignore or disallow command names and functions with embedded spaces.
* Would running the bash '-x' option provide a better basis for the scan, or is the source better?
* Or, what?
* I have a few scripts that write other scripts (templates, with an intervening editing session). I suppose that if I have a utility that can scan a "non-recursive" script, I could use the utility recursively?

**"Specs"**

* I only want the list to include external commands; if Bash internals are included, I would prefer that they be listed separately.
* There are quite a few Bash internals that have external equivalents, e.g., 'echo' and 'test'. I need to be able to distinguish between the two like-named commands. Is a format like '/bin/test', for example, sufficient to distinguish between the two?
* Ignore first <words> followed by '()'
* Ignore everything to the right of a '#' not quoted or escaped.
This gets pretty complicated on multiline quotes with embedded quotes, i.e.:
- \>"...'...'..."<
- \>"...'...'..."<
- \>"...\"...<
- etc.
* First <word> on a line.
* First <word> following a ';'.
* First <word> following a '|'.
* First <word> following a '$(', or '`'.

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

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

r_bash

Create bash scripts 100x faster using libray

# bash-sdk 🔥

A bash library to create standalone scripts.

https://ourcodebase.gitlab.io/bashsdk-docs/

## Features ✨

There are some features of bash-sdk are mentioned here.

OOPS like code 💎.
Module based code 🗂️.
Similar functions to python 🐍.
Standalone script creation 📔.

## Beauty 🏵️

Checkout the ui of this cli project here.

## General 🍷

There are some rules or things to keep in mind while using this library.

The rules are mentioned here.

## Installation 🌀

Just clone it to anywhere.

git clone --depth=1 https://github.com/OurCodeBase/bash-sdk.git

## Modules 📚

These are the modules created in bash-sdk library. You can read about their functions by clicking on them.

[ask.sh](/docs/ask)
cursor.sh
[db](/docs/db)
file.sh
[inspect.sh](/docs/inspect)
os.sh
[package.sh](/docs/package)
repo.sh
[say.sh](/docs/say)
screen.sh
[spinner.sh](/docs/spinner)
string.sh
[url.sh](/docs/url)

## Structure 🗃️

File structure of bash-sdk is like:

bash-sdk
├── docs # docs for bash-sdk.
├── _uri.sh # helper of builder.
├──
builder.sh
└── src
├──
ask.sh
├──
cursor.sh
├──
db.sh
├──
file.sh
├──
inspect.sh
├──
os.sh
├──
package.sh
├──
repo.sh
├──
say.sh
├──
screen.sh
├──
spinner.sh
├──
string.sh
└──
url.sh

## Compiler 🧭

Compiler does combine all codes in a standalone bash file.

bash
builder.sh -i "path/to/input.sh" -o "path/to/output.sh";

input file is the file that you are going to compile.
output file is the standalone result file.

Then you can directly execute output file without bash-sdk library.

## Queries 📢

If you have any questions or doubt related to this library you can directly ask everything [here](
https://github.com/OurCodeBase/bash-sdk/issues).

## Suggestion 👌

bash-lsp to your code editor to get auto completions.
[shellcheck](https://github.com/koalaman/shellcheck) to debug bash code.
cooked.nvim code editor to get best compatibility.

## Author 🦋

Created By [@OurCodeBase](https://github.com/OurCodeBase)
Inspired By @mayTermux

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

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

r_bash

Trouble formatting output of PS command

I'm trying to get a formatted list of the 5 most CPU intensive processes using the PS command. This works but I'm not sure how to align all values to the left.

I run the command like so:

ps --no-headers -Ao comm:21, -o pid:6, -o pcpu:6 --sort=-pcpu | head -5

which produces the following output:

Isolated Web Co 97231 7.9
firefox 32302 5.5
Isolated Web Co 175732 3.7
Hyprland 689 2.1
RDD Process 45174 1.9

Now I'd like to align the second column to the left but I'm not sure how to do this. Piping it into column -t messes up the layout because of the spaces in the first column's values:

Isolated Web Co 97231 8.1
Isolated Web Co 175732 5.7
firefox 32302 5.4
Hyprland 689 2.1
RDD Process 45174 2.0

I'm probably missing something obvious. Can anyone point me in the right direction? It would be much appreciated!

https://redd.it/18xwvec
@r_bash

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