this post was submitted on 03 Aug 2023
24 points (90.0% liked)

Linux

47231 readers
1145 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
24
Naming Bash scripts (lemmy.dbzer0.com)
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
 

I'm crossposting this here

A) So I can see if I know how to cross post lol

B) To bring attention to the [email protected] community here, as it it woefully small and could use some publicity, especially to those who can help more than the noobs seeking it out

C) Hopefully get the answer I seek.

...did the crosspost work? (Ayy alright!)

top 15 comments
sorted by: hot top controversial new old
[–] [email protected] 16 points 1 year ago* (last edited 1 year ago)

Just name your script with your credit card numbers, so you're pretty sure you won't have any collisions... Don't hesitate to let me know when you've done it :)

[–] [email protected] 5 points 1 year ago* (last edited 1 year ago) (2 children)

Hahaha when I click the link from /all it takes me to

https://zerobytes.monster/c/beautifulfemales

When I go to the comments first then click the link it goes to

https://lemmy.dbzer0.com/post/1464137

[–] [email protected] 2 points 1 year ago

Hi there! Looks like you linked to a Lemmy community using a URL instead of its name, which doesn't work well for people on different instances. Try fixing it like this: [email protected]

[–] [email protected] 1 points 1 year ago

Lmao yeah something is going on with linkage, the other day someone linked me to a lemmy comment but it would only show me a different comment, and others could load the right one correctly. No clue what that's about.

[–] [email protected] 3 points 1 year ago (1 children)

which commandname will tell you if there's a command already by that name on your system without having to run anything.

This only finds things in places stored in the $PATH environment variable, though.

You could query your package manager to see what packages for your distribution might contain the command name, but 1) that will also turn up support files and the like and 2) Not all distros have the same commands, especially once you get beyond the core Unix/Linux command set.

e.g. on a system with apt, I can run apt contains commandname and get a list of everything containing "commandname"

Another user suggested prefixing with my_, but you might consider using your initials, a short form of your username or some other identifier instead. e.g. Everyone is "me/my" to themselves, but fewer people share your initials.

Also, a suffix might actually be a marginally better choice depending on your tab-completion preferences.

There's precedent for some actual "official" commands using a .suffix style, especially when multiple packages have their own version of a particular command, or a minor variant. On my computer I have things such as uncompress.real, vim.tiny, lzip.plzip and telnet.netkit, for example.

Something like scriptname.arcslime would fit right in, whether or not scriptname is a thing in its own right or not.

[–] [email protected] 1 points 1 year ago

I like the .suffix idea, I may run with that, thanks!

[–] [email protected] 3 points 1 year ago

If you use them for your use only, or want them "cleanly" organized, consider prefixing it with something personal to you (or a generic one such as my_). For example, I'd prefix them with l_: my_rename_photos.sh, my_lightson.sh, etc.

If there's a lot of them, write a wrapper script which would call the individual scripts from a common location (/usr/share/my-scripts/). Then, you can only make sure your wrapper script is aliased/moved in the PATH. Example: my rename, my lightson, etc.

[–] [email protected] 2 points 1 year ago (1 children)

If you're using a Debian based distro, you can search through contents of packages to see if there's a conflict:

E.g. apt-file search /usr/bin/sh

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago)

This is the first time I see dnf provides par, let me check on ubuntu server...

EDIT: ugh, it isn't a good as dnf version, but manageable... thanks.. at least this ease the search of a file/lib/binary location...

[–] [email protected] 2 points 1 year ago (1 children)

Don't know the site you're looking for - might have never seen it. But I saw a tip a while back: name YOUR scripts something like ",script" (with a comma, or other confortable to type character as 1st character). It would be odd to ever find a colision.

I just don't do that though! Too odd!

[–] [email protected] 4 points 1 year ago (1 children)

related practice (and maybe less odd) - I prepend some function names to "group" them.

Before using topgrade I wrote some functions to automatically update package managers e.g. apt, cargo, flatpak. so I created uu_apt, uu_cargo, etc. Prepending plays well with the Tab autocomplete in the shell.

[–] [email protected] 1 points 1 year ago

This is basically what I've done so far, actually. I just want to polish it up just a hair enough that I can send it to friends or transfer it between distros, the name is terrible but descriptive (and long, but tab-complete so I said fuck it for the time being). Just need to rename it and change a few lines to "$USER" to make it a bit more polished.

For instance one I really need to rename is just a batch converter using ffmpeg, atm I just called it batchffmpeg but that is too long, might just call it bffmpeg and keep it rolling, short enough and likely not taken. The others I'm more worried about conflicts but I suppose as someone else pointed out the tried and true "band name" method (think of one and just search "google" to see if taken) should handle it. Never thought about that lol, one of those solutions that's just too simple I missed it while looking higher.

[–] [email protected] 2 points 1 year ago (1 children)

frankly if I already had the names, I would just search for " cli" or " bash" and see what comes up.

[–] [email protected] 1 points 1 year ago

Genius, now I just need to think of the names for one or two. No clue why I just didn't think of that lol. Thanks!

I need to learn to bookmark shit like this [link I can't find].

[–] [email protected] 1 points 1 year ago

My script names are basically

downloadallmystuffbackplease.sh

bbutimnotonmyrpi4.sh

aptthewholething.sh

jesusimfuckingdum.sh

load more comments
view more: next ›