this post was submitted on 19 Mar 2024
96 points (94.4% liked)

Linux

48287 readers
613 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
 

What do you advice for shell usage?

  • Do you use bash? If not, which one do you use? zsh, fish? Why do you do it?
  • Do you write #!/bin/bash or #!/bin/sh? Do you write fish exclusive scripts?
  • Do you have two folders, one for proven commands and one for experimental?
  • Do you publish/ share those commands?
  • Do you sync the folder between your server and your workstation?
  • What should've people told you what to do/ use?
  • good practice?
  • general advice?
  • is it bad practice to create a handful of commands like podup and poddown that replace podman compose up -d and podman compose down or podlog as podman logs -f --tail 20 $1 or podenter for podman exec -it "$1" /bin/sh?

Background

I started bookmarking every somewhat useful website. Whenever I search for something for a second time, it'll popup as the first search result. I often search for the same linux commands as well. When I moved to atomic Fedora, I had to search for rpm-ostree (POV: it was a horrible command for me, as a new user, to remember) or sudo ostree admin pin 0. Usually, I bookmark the website and can get back to it. One day, I started putting everything into a .bashrc file. Sooner rather than later I discovered that I could simply add ~/bin to my $PATH variable and put many useful scripts or commands into it.

For the most part I simply used bash. I knew that you could somehow extend it but I never did. Recently, I switched to fish because it has tab completion. It is awesome and I should've had completion years ago. This is a game changer for me.

I hated that bash would write the whole path and I was annoyed by it. I added PS1="$ " to my ~/.bashrc file. When I need to know the path, I simply type pwd. Recently, I found starship which has themes and adds another line just for the path. It colorizes the output and highlights whenever I'm in a toolbox/distrobox. It is awesome.

you are viewing a single comment's thread
view the rest of the comments
[–] jlsalvador@lemmy.ml 28 points 8 months ago* (last edited 8 months ago) (3 children)
#!/usr/bin/env bash

A folder dotfiles as git repository and a dotfiles/install that soft links all configurations into their places.

Two files, ~/.zshrc (without secrets, could be shared) and another for secrets (sourced by .zshrc if exist secrets).

[–] clmbmb@lemmy.dbzer0.com 10 points 8 months ago (1 children)

#!/usr/bin/env bash

This is the way!

[–] GravitySpoiled@lemmy.ml 5 points 8 months ago (2 children)
[–] unlawfulbooger@lemmy.blahaj.zone 20 points 8 months ago* (last edited 8 months ago) (2 children)

because bash isn’t always in /usr/bin/bash.

On macOS the version on /usr/bin/bash is very old (bash 3 I think?), so many users install a newer version with homebrew which ends up in PATH, which /usr/bin/env looks at.

Protip: I start every bash script with the following two lines:

#!/usr/bin/env bash
set -euo pipefail

set -e makes the script exit if any command (that’s not part of things like if-statements) exits with a non-zero exit code

set -u makes the script exit when it tries to use undefined variables

set -o pipefail will make the exit code of the pipeline have the rightmost non-zero exit status of the pipeline, instead of always the rightmost command.

[–] GravitySpoiled@lemmy.ml 4 points 8 months ago
[–] bizdelnick@lemmy.ml 0 points 8 months ago

/bin/sh is always /bin/sh.

[–] clmbmb@lemmy.dbzer0.com 8 points 8 months ago

#!/usr/bin/env will look in PATH for bash, and bash is not always in /bin, particularly on non-Linux systems. For example, on OpenBSD it's in /usr/local/bin, as it's an optional package.

If you are sure bash is in /bin and this won't change, there's no harm in putting it directly in your shebang.

[–] GravitySpoiled@lemmy.ml 2 points 8 months ago

dotfiles

Thanks! I'll check them out. I knew the cooncept existed but so far I didn't dig deep into managing them. This is my start I guess https://wiki.archlinux.org/title/Dotfiles

[–] mryessir@lemmy.sdf.org 1 points 8 months ago

Instead of a install skript, check out GNU stow. It does exactly that and you can interqctively choose which things to install/symlink.