I'm trying to create a bash alias that would act as a prefix, and could be parsed without needing to use a space. Basically, I have a set of commands that all start with the same first few characters, and I would like to prefix them with another command before running it without having to type that prefix out every time.
In other terms, I want to be able to create an alias that would work like this: alias pref="sudo commandtoprefix"
would make it so that running prefcommand
would run sudo commandtoprefixcommand
. Note the lack of space, it is important.
I think I was able to do it at some point by simply doing as described, but for some reason it now doesn't work and returns a command not found
error.
I've stumbled upon this answer, but it is describing a function and therefore requires the use of a space, which doesn't exactly fit my needs.
Is there a way I could do this with aliases or functions that wouldn't require using a space?
prf
withsudo commandtoprefix
anywhere in the command line. But the replacement cannot be the originally string. Sopref
forsudo commandtoprefix
is not possible, but you can useprf
, for example:bind '"prf": "sudo commandtoprefix"'
. – muru Mar 31 '22 at 09:27