You are not logged in.
Hi all!
I'm not very well-versed in the art of bash scripting or anything and I am having some trouble doing an alias that uses two arguments.
My case:
My command:
"openssl aes-256-cbc -a -salt -in a.txt -out a.txt.aes"
What I wanted to do was an alias like this:
alias encrypt="openssl aes-256-cbc -a -salt -in $1 -out $2"
But it's not working. Actually, even using just the $1 and leaving a fixed string as $2 is not working.
Can anyone give me some help? Thanks!
Last edited by Wasser (2012-05-09 22:45:56)
Offline
You gotta use single quote's (not sure of the correct English term):
' instead of "
Also, remember to reload your .bashrc after changing it.
Last edited by Unia (2012-05-07 18:03:10)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Afaik, that's not possible with bash's aliases. But you can define a function:
encrypt() { openssl aes-256-cbc -a -salt -in "$1" -out "$2"; }
Offline
Use a function, or make a script and stick in your path.
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Thanks to all.
I will use a function (the single quote does not work).
But why does this happen?
Offline
But why does this happen?
Aliases simply don't take arguments, functions do (just like the mathematical functions).
Offline
Wasser wrote:But why does this happen?
Aliases simply don't take arguments, functions do (just like the mathematical functions).
Thanks
Offline
Aliases simply don't take arguments, functions do (just like the mathematical functions).
Well, though one can of course use arguments with aliases, e.g.
alias p='sudo pacman'
still allows you do specify options, etc of course, such as:
p -Syu foobar
Might be "better"/less confusing to say that an alias is just a simple string replacement, and for more "complicated" things one needs indeed to e.g. use a function.
Offline
Sure, I often use aliases that way. as
alias foo="bar baz"
and
foo () { bar baz $1; }
are equivalent:
$ foo <some argument>
Offline
Ok. So actually the problem is replacing arguments in the middle of the command.
Offline
Ok. So actually the problem is replacing arguments in the middle of the command.
Correct! You might also be interested in this recent thread, from about 6 posts down onwards: https://bbs.archlinux.org/viewtopic.php?id=140146
Please remember to mark the thread solved .
Offline