r_bash – Telegram
how to make my bash noscript take lesser ram?

So, I wrote a bash noscript that would randomize my wallpaper from a folder and i made it such that it starts up when my pc boots up in hyprland.conf file but there is one drawback and that is gradually it takes up all the ram.
HOW do i make it such that it doesn't take all the ram?

https://redd.it/1j5fe56
@r_bash
Tar2Deb

Pure bash noscript that converts a tar file into a deb file

in order to install tar2deb you need wget, note only works for debian based distros.

features

automatically move images in the extracted tar directory that holds a subdirectory with the most images then export it as a variable then moves to the deb directory, the deb directory is needed in order to create a .deb file, it uses imagemagick to move each image by dimension, before the dimensions and after is extracts the tar file it will ask the user what does want the package name be, does not allow numbers except 2, then the name of the package the user chooses will be exported as a variable, then it will ask the user what is version of your package, once the user chosen its version for the package it will be exported as a variable then combine those to variables like this $PackageName-$Version then it will create the directory with those 2 variables then it will ask the user what name of the maintainer, whatever name the user decides will be exported as a variable, then it asks the user what is the package about, whatever the users type will also because exported as variable, then it will create the control file in the deb dir DEBIAN folder, then once the control file is created, it will create the directories in the deb directory, then it will find a graphical executable file (excluding binary files) and move to deb_dir/usr/bin after it does then it will go the dimensions after it moves the dimension it will ask the user a yes or no prompt asking if it wants to rename all image files moved into one name if the users say no then it will ask the user if it wants to rename a file from the numerical list and whatever numbers it chooses it will prompt the user what the name to be for the file then it combine that name with the file extension and renames the chosen file with the name that user choose, then it create a desktop if there is not an desktop file in the tar directory it will ask the user if it wants to create a desktop since there is not located in tar directory if the users say user then it do a prompt asking the user what executable file it wants to choose for desktop file then it will show a numerical list showing a list of images and whatever image the user chooses will be the icon of the desktop file once the desktop file is

how to install tar2deb

sudo apt install wget && wget https://github.com/GitXpresso/Tar2Deb/releases/download/v.1.0.0/tar2deb-1.0.0.deb && sudo apt install -y ./tar2deb-1.0.0.deb

https://redd.it/1j5u1xh
@r_bash
backup copy of .bashrc for the root directory?

i found a copy of .bashrc in /etc/skel but the .bashrc file in /root is another one

https://redd.it/1j6v9l7
@r_bash
Command completion suggestions while typing?

How to get the behaviour of when I type in say, lo or lon, a faded g_cmd appears after the cursor (for a command long_cmd), which after pressing <TAB>, gets un-faded/is written to the input line? I tried looking but couldn't really find anything. I just got fzf, it provides completion but only after you type in a command. TIA.

https://redd.it/1j6o5zg
@r_bash
HELP Please. The while loop is running before SSH has ended completely.

https://preview.redd.it/6yv2drjx0ine1.png?width=687&format=png&auto=webp&s=afaef25c281cf083cbc5685e7552203ef6375e58

https://preview.redd.it/f622kvze1ine1.png?width=596&format=png&auto=webp&s=943b60670c3d4ce0e63d5e143673302c5db97f08

So I wrote this code to automate ssh and storing passwords in OverTheWire challenge.
Problem : When I press Enter nothing happens.
What I think the problem is : The while loop starts running before the SSH ends completely. Even GPT did not help.
Can someone please tell me wat the issue is, and how to fix it?

https://redd.it/1j6lxab
@r_bash
In theory, could all quoting be achieved with just the backlash character? Or are there instances where single quotes are required

In other words, are single quotes supported by necessity or pure convenience?

https://redd.it/1j7jak3
@r_bash
exitcode from a pipe inside an if statement

Backstory, SomeCommand produces 15-20 lines of output that the user needs to read. Sometimes it fails, most of the time in a known way.
My approach has been
if [[ `SomeCommand |tee /dev/stderr |grep -c Known Error; Xcode=${PIPESTATUS[0\]}` -gt 0 \]\]; then
echo Known error $Xcode
else
echo Unknown error $Xcode
exit
fi

/dev/stderr goes to the console so the user can see the output
grep finds the known error string & handles it correctly
but...

$Xcode is always 0 :(
If $Xcode is >0 and it's not the known error, the noscript should terminate.

Have been using true, false & echo as SomeCommand for testing, maybe this is an issue.

It's not the |tee part
if [[ `false |grep -c Known Error; Xcode=${PIPESTATUS[0\]}` -gt 0 \]\]; then echo found $Xcode; else echo not found $Xcode; fi
not found 0

It's something to do with the if [[ `...` \]\] bit
false |tee /dev/stderr |grep -c Known Error; Xcode=${PIPESTATUS[0\]}; echo $Xcode
0
1


If it's changed to if [...\], then it's always 1

if [ `echo "Known Error" |tee /dev/stderr |grep -c "Known Error"; Xcode=${PIPESTATUS[0\]}` -gt 0 \]; then echo found $Xcode; else echo not found $Xcode; fi
Known Error
found 1


if [ `echo "Unknown Error" |tee /dev/stderr |grep -c "Known Error"; Xcode=${PIPESTATUS[0\]}` -gt 0 \]; then echo found $Xcode; else echo not found $Xcode; fi
Unknown Error
not found 1


Someone please put me out of my misery.

https://redd.it/1j7q8as
@r_bash
New to Bash Scripting and Sysadmin? Check Out My Tool: Linux Console Manager (Open Source - All Feedback Appreciated)

Hi r/bash community!

I'm a new Redditor, and I wanted to share a simple bash noscript I've been working on called Linux Console Manager. I'm actually from Korea and haven't used Reddit much before, but I'm excited to share this with you all!

As someone who occasionally does Linux system administration, I found myself constantly typing the same commands over and over. So, I created this little tool to streamline those common tasks and make my life a bit easier. I thought it might be helpful for others too, especially those who are newer to Linux or just want a quicker way to manage their systems from the terminal.

Key Features:

System Monitoring: Tired of typing top, free -m, df -h, and ifconfig separately? Linux Console Manager gives you a quick, consolidated overview of essential system metrics like CPU usage, memory consumption, disk space, and network stats in one place!
Service Control: Managing system services like Apache, Nginx, or MySQL can be a bit tedious with systemctl. This noscript lets you easily start, stop, restart, and check the status of your services through a simple menu. No more struggling to remember those commands!
Process Management: Quickly identify and manage running processes. Need to find that resource-hogging process? Linux Console Manager helps you easily find and even kill processes directly from the noscript.
Network Utilities: Basic network troubleshooting tools like ping and traceroute are built right in, making it convenient for quick network checks.
\[Add other key features of your noscript here - Be specific! For example:\]
User Management: Easily add, delete, or modify user accounts with simple menu options.
Log Viewing: Quickly access and view common system logs like /var/log/syslog or /var/log/auth.log.
Package Management (Debian/Ubuntu based): Simple interface for updating packages or searching for new ones using apt.

The noscript is completely open source and available on GitHub: https://github.com/forsys02/linux\_console\_manager

https://preview.redd.it/1avm3lnnsune1.png?width=458&format=png&auto=webp&s=25a753e1bb074cbc0dbd4e8f4a93c8caa952de5f

I would love for you to try it out and give me your feedback! I'm really open to suggestions for improvement and new features. Specifically, I'm curious about:

Is the menu structure intuitive and easy to navigate?

Are there any features you think are missing or could be more useful?
Do you find it helpful in your daily system administration tasks?
I'd especially appreciate feedback from both experienced sysadmins and those who are newer to Linux. Let me know what you think!

This is a project I'm working on in my spare time, and I hope it can be helpful to others in the community.

Thanks for checking it out! Happy noscripting! 😊



https://redd.it/1j7x3vj
@r_bash
i want to put raw code into a variable by utilizing heredoc, but it seems that the outer syntax is interpreting things

what i'm trying to do is make a noscript that would put some boilerplate code into files, so i need raw unexecuted code in a variable.

the smallest example of my problem can be shown with this code:
DEFAULT_PROGRAM=$(cat <<'EOF'
\)
EOF
)
echo $DEFAULT_PROGRAM


regardless of which of the 4 combinations of fixes i apply here (having quotes around EOF or not, and having the inner parenthesis escaped or not), it seems to never output just the raw parenthesis. Either it outputs the escaping character too \), or it errors out by saying:
EOF: command not found
syntax error near unexpected token `)'
`)'


as i understand it, it's the outer syntax $(cat ... ) that breaks it.

is there an elegant solution to this so that i don't have to resort to using echo with lots of character escaping?

https://redd.it/1j8q85k
@r_bash
What is the purpose of /dev/tty ?

Please hear me out. So, reading about special devices like tty, tty0, pst1...pstn I understand in loose terms that terminal emulators (like the ones you bring up with ctrl+t ) are special devices under /dev/pts/<some_number> . Now, tty0 appears to be a terminal associated to kernel itself (I still don't know what that means). But tty? I only know that it points to the current terminal being used but I don't know exactly what to make of that and how it pertains to the following humble little snippet I wrote:

#!/bin/bash

while read -r filename
do
echo "Current fie: ${filename}"

read -p "Delete ${filename} ? " response < /dev/tty

if [[ $response = 'y' || $response = 'Y' ]]
then
echo "response was yes"
echo "Deleting ${filename}"
tar vf pdf_files.tar --delete "${filename}"
echo
else
echo "skipping"
fi
done < <(tar tf pdf_files.tar)

You'll notice that in the line that contains the read -p command I had to redirect input from tty. I had chatGPT suggest that to me after many failed attempts at getting my little noscript to run correctly because I didn't understand why $response variable would be automatically set to something and the noscript wouldn't even wait at the prompt for me to enter something. I had my eyes OPENED today -- and in a frustrating way -- as to how many little tricks and things one must take into account when learning bash noscripting.

So, going back to the noscript, why did I even need to do that or more importantly, WHEN do I need to do that kind of trick again?

p.s. I've been learning from time to time bash noscripting for like the past 3 o 4 months and I know I have to learn a lot more, but Jesus, the journey feels never-ending.

https://redd.it/1j98bb0
@r_bash
How to use "cut" correctly

Hi there,


I have a file with urls in it, followed by a little denoscription.

`www.lol.com`///denoscription

I want to use dmenu to open it in a brower, at the moment, I'm using this line :

cat ~/world/Documents/bookmarks | ~/.config/sway/noscripts/mydmenu -p "Bookmarks:" | xargs -0 -I {} firefox "{}"

But sometimes it fails because xargs takes the full line with the spaces and the denoscription. How would you do to still print the whole line in dmenu, but only takes the first part (url) into args ?

https://redd.it/1j9gewb
@r_bash
Collections of very useful Bash Functions

I use Bash a lot working with applications, systems, containers or networks, mgmt & integration.

I've found and frequently use a few really useful Bash Github repositories with collections of Bash "Functions" that you can use in your own Bash noscripts.  

I've learned  a lot from them and have to say my Bash noscripts now have capabilities I'd probably never been smart enough to create myself. In your own noscript(s) you just "source" the file you create or download from the following URLs: 

I am sharing this info in case someone else finds them useful.

# Collections of Functions for Bash

GUI'sEasyBashGUI: **https://github.com/BashGui/easybashgui/blob/master/docs/install.md**

>Simplified way to code bash made GUI frontend dialogs!

Script-Dialog: **https://github.com/lunarcloud/noscript-dialog?tab=readme-ov-file**

>Create bash noscripts that utilize the best dialog system that is available. Intended for Linux,
but has been tested on macOS and Windows, and should work on other unix-like OSs.

If it's launched from a GUI (like a .desktop shortcut or the dolphin file manager)
\- it will prefer kdialog in Qt-based desktops and zenity in other environments.

If neither of those are available
\- then relaunch-if-not-visible will relaunch the app in a terminal so that a terminal UI can be used.

If it's launched in a terminal
\- It will use whiptail or dialog

If neither of those are available, then it will fallback to basic terminal input/output with tools like read and echo

Collections of General Bash FunctionsBashMatic: **https://github.com/kigster/bashmatic**

>Bashmatic is a BASH framework, meaning its a collection of BASH functions (almost 900 of them) that, we hope, make BASH programming easier, more enjoyable, and more importantly, fun \- due to the library’s focus on providing the developer with a constant feedback about what is happening, while a noscript that uses Bashmatic’s helpers is running.

Bash-Concurrent: **https://github.com/themattrix/bash-concurrent**

>A Bash function to run tasks in parallel and display pretty output as they complete.

https://redd.it/1j9lkzi
@r_bash
A noscript to install llama-cpp-python with CUDA enabled

I made an auto-install noscript for myself that I thought some people might find useful or interesting. I have seen posts online where some have claimed to be unable to figure out a way to install llama-cpp-python so for those people maybe this can help and for everyone else this is just a plain fast way to do this.

1. Optionally installs Conda (which I personally recommend doing)
2. Installs the latest version of llama-cpp-python with CUDA enabled from the official llama-cpp-python GitHub repo.

GitHub - llama-installer.sh

FYI, if you choose to install Conda it links to this noscript: GitHub - install_conda.sh

Cheers guys and have a great day.

-J

https://redd.it/1j9nxxn
@r_bash
how do you combine this 2 parts: touch + strftime ("%F")?

Hi, I'd like to do touch with date today like noum of the file...

how do you do that?

example: touch ..... make this file 2025-03-12

Thank you and regards!

https://redd.it/1j9tnlh
@r_bash
xarg or sgrep or xmllint or...

All I am trying to do is get

noscript="*"

file="*"

~~~~~

noscript="*"

file="*"

~~~~~

etc


**noscript xml path is:**

/MediaContainer/Video/@noscript

(i think that is how you write noscript being the attribute?).


**file xpath is** :


/MediaContainer/Part/@file

and just write it to a file.
The "file" is always after the noscript so I am not worried about something changing in the structure.

The closest I got (but for only 1 and I have no idea how to get the pair of them) is

find . -iname '*.xml' -print0 | \
xargs -0 -r grep -ro '<Video[ \t].*noscript="[^"]*"' | awk -F: '{print $3}' >>test.txt

Any help would be appreciated.

https://redd.it/1j9zugv
@r_bash
is it crazy change rm by mv (file or dir/) ~/.local/share/Trash/files/

Hi, is it possible to do an auto-change from rm to mv file/dir ~/.local/share/Trash/files/ ?

This would avoid being wrong to erase something that I shouldn't erase, so when I do RM Bash changes the RM command for the other command that I put up.

If this is not complicated or just experts. I am not. You already see what I am wrong ...

Thank you and Regards!

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