mIRC Home    About    Download    Register    News    Help

Print Thread
Passing arguments containing spaces to a command #265962 24/08/19 02:32 AM
Joined: Aug 2019
Posts: 3
F
FraPooChino Offline OP
Self-satisified door
OP Offline
Self-satisified door
F
Joined: Aug 2019
Posts: 3
How would you pass "a b c" and "1 2 3" to a command and still be able to reference these parameters as $1 and $2 in the corresponding alias?

For the sake of clarification, the following alias would print "a b c 1 2 3" instead of "a b":

Code
alias test {
  echo -g $1 $2
}

Re: Passing arguments containing spaces to a command [Re: FraPooChino] #265965 24/08/19 10:23 AM
Joined: Jan 2004
Posts: 1,214
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,214
only way is to call this as an identifier.

Instead of
/test a b c 1 2 3
it would be
//noop $test(a b c,1 2 3)

The tokenize command can group them together by using something besides space as delimiter:
//tokenize 46 a b c . 1 2 3 | echo -a $1 and $2
however as soon as you called your test alias as a /command
//tokenize 46 a b c . 1 2 3 | /test $1 $2
... then your /test alias would not retain the original definition of $1

Re: Passing arguments containing spaces to a command [Re: maroon] #265966 25/08/19 02:21 AM
Joined: Aug 2019
Posts: 3
F
FraPooChino Offline OP
Self-satisified door
OP Offline
Self-satisified door
F
Joined: Aug 2019
Posts: 3
I already knew I could use identifiers but I was wondering if there was an elegant way to do it with commands, I guess there isn’t…

I’ll just stick to identifiers only.

Re: Passing arguments containing spaces to a command [Re: FraPooChino] #265968 25/08/19 10:38 AM
Joined: Mar 2010
Posts: 144
Masoud Offline
Vogon poet
Offline
Vogon poet
Joined: Mar 2010
Posts: 144
There is, as maroon mentioned you can use a different delimiter and /tokenize.


Nothing...
Re: Passing arguments containing spaces to a command [Re: Masoud] #265970 25/08/19 11:04 AM
Joined: Aug 2019
Posts: 3
F
FraPooChino Offline OP
Self-satisified door
OP Offline
Self-satisified door
F
Joined: Aug 2019
Posts: 3
Sure, but if I’d like all my custom commands to have this nice feature, I’d have to come up with a common delimiter I could use in all of them. So I’d have to use a delimiter that wouldn’t appear in a regular string, in other words a character which doesn’t appear on a keyboard. Now, let’s say I choose `$chr(31)`. I can use `tokenize 31 $1-` and then I’ll get my parameters nicely numbered but I still need to format the parameters when calling my fancy aliases. So I’d have to add `$chr(31)` between each parameter and that’s why it doesn’t seem to be an elegant solution to me.

Last edited by FraPooChino; 25/08/19 11:05 AM.