this post was submitted on 06 Apr 2025
19 points (100.0% liked)

Linux Questions

1569 readers
2 users here now

Linux questions Rules (in addition of the Lemmy.zip rules)

Tips for giving and receiving help

Any rule violations will result in disciplinary actions

founded 2 years ago
MODERATORS
 

i'm trying to basically make a shortcut for krabby (see link) so i dont have to type <krabby name (pokemon name)> to see a specified pokemon. basically how can i make a script that passes the and to the output of what i type next?

top 12 comments
sorted by: hot top controversial new old
[–] sudo_aptget_karma@lemmy.world 6 points 1 day ago* (last edited 1 day ago)

this sounds like something you can do by setting up a command alias as well:

alias [pokemon name] = '[command and options go here]'

i.e. alias update='sudo apt-get update && sudo apt-get upgrade -y'

or in your case: alias pikachu = 'krabby name pikachu'

[–] tofubl@discuss.tchncs.de 6 points 1 day ago (1 children)

Not 100% clear what you want to achieve, but you probably want an alias.

[–] Telorand@reddthat.com 3 points 1 day ago* (last edited 1 day ago) (1 children)

They'd have to make an alias for every Pokemon. What they need is a simple program that reads input and executes the krabby command with that input as a parameter, then make it loop until it gets an exit command (or just Ctrl+C).

[–] myfavouritename@beehaw.org 2 points 1 day ago* (last edited 1 day ago) (1 children)

No, I don't think they'd have to make an alias for every Pokemon. The person you're responding to is correct.

Assuming that the original poster wants to continue to specify which Pokemon they want to see, they'll at least have to type that in, right?

If we're comfortable with that as a requirement, then an alias setting "k" to equal "krabby name" will work when you enter any Pokemon name after "k".

[–] Telorand@reddthat.com 1 points 1 day ago

I suppose that's true, though with their vague requirements, I was imagining something more like a REPL, so they could enter as many Pokemon as they wanted in a row, without needing an alias every time.

[–] Ephera@lemmy.ml 4 points 1 day ago

I don't quite understand. Do you just want to type e.g. k pikachu and that expands to krabby name pikachu ? Can you give an example of how you'd want to use it?

[–] Sunsofold@lemmings.world 1 points 1 day ago

QoL hacks FTW.

Found this on AskUbuntu. A few different ways there with a couple being quite easy. Probably going to try one of these myself in a bit.

[–] stoy@lemmy.zip 1 points 1 day ago

Do you know about tab autocomplete?

It would probably mean that you can just enter something like

$ kra<TAB> charmander<ENTER>
[–] couch1potato@lemmy.dbzer0.com 2 points 1 day ago (1 children)

You said see link but there's no link

[–] HotsauceHurricane@lemmy.one 2 points 1 day ago (1 children)

Still not clear what you're trying to do but assuming you're trying to manipulate the krabby output with a different program, the other poster's link on aliases should help you out. See the bottom section there on bash functions.

So for example if you're trying to store a krabby output to a specific folder, something like this:

alias_name () { mkdir /path/%1 && krabby name %1 | xargs mv -t /path/%1 }

So in theory, typing something like alias_name charizard would, in this order, create a new folder at /path/charizard, run krabby charizard, and then place the output charizard file inside your new /path/charizard folder.

I say in theory because I don't know what output krabby gives you and I don't know bash, I just googled how piping with xargs works right now. But maybe with this idea you can figure it out.

[–] Ruminare@feddit.org -5 points 1 day ago

Try asking Google Gemini or chatgpt to write the code for you. Most will these days. Then you can refine it based on what you're actually trying o achieve.