this post was submitted on 06 Feb 2024
124 points (96.3% liked)

Linux

48364 readers
1753 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Examples could be things like specific configuration defaults or general decision-making in leadership.

What would you change?

you are viewing a single comment's thread
view the rest of the comments
[–] Contort3860@links.hackliberty.org 4 points 9 months ago (1 children)

Just curious, why a script instead of just a bash alias or something like it?

[–] Samueru@lemmy.world 3 points 9 months ago* (last edited 9 months ago) (1 children)

alias totally works, but if you want to simplify it for multiple package managers then it is better to use a script.

Like this example that when the user types pkginstall vim, pkginstall would be a script in path that would do the operation regarless of the package manager:

# Install with 'pacman' (if available)
if command -v pacman >/dev/null 2>&1; then
    sudo pacman -S $@ || exit 1
fi

# Install with 'apt' (if available)
if command -v apt >/dev/null 2>&1; then
    sudo apt install $@ || exit 1
fi

# Install with 'dnf' (if available)
if command -v dnf >/dev/null 2>&1; then
    sudo dnf install $@ || exit 1
fi

They could even install it in their ~/.local/bin, and as long as their distro makes that part of PATH (which arch does not kek) by just using that same home with another distro they already could install/remove packages and update using those wrapper scripts regardless of the distro.

If you are wondering why the script needs to check if the package manager exists, it is because when testing it I discovered that if the first one is not installed it will cancel the operation and not continue, and if I remove the exit 1 it will attempt to use the next package manager when canceling the operation with ctrl+c.

Thanks for the solid explanation.

As a noob that doesn't change my distro too often, I never would have thought of something like this.