eval Change the behaviour of a set of commands |
||||
Usage |
||||
eval [-q] [-r=<window:integer>] <command:string> |
||||
Description |
||||
This command is useful to execute variable command sequences. <command> is first evaluated as a normal parameter (thus identifiers and variables are substituted) then the evaluated string is executed as a command sequence. -q causes eval to run quietly and don't display any errors in the inner command. -f causes eval to ignore the errors inside <command> and continue execution. This command may be used to rebind the <command> to a specified window. <command> shares the local variables with this command scope so you can easily exchange data with it. Remember that <command> is still a normal parameter and it must be enclosed in quotes if you want it to be a complex command sequence. eval propagates the <command> return value. WARNING: If some part of the <command> comes from external input you MUST sanitize it by using $escape() in order to avoid command injection. Note that nicknames, usernames, hostnames, channel names and any kind of text that isn't generated under your control may contain malicious code. For instance, if you try to eval the string built by concatenating echo and the result of $channel.name inside a channel named #test;quit (yes, that's a valid channel name) you'll obtain a disconnection as a side effect. To avoid this you need to use $escape() around $chan.name. |
||||
Switches |
||||
|
||||
Examples |
||||
# evaluate a variable command if(%somecondition)%tmp = "echo yeah" else %tmp = "echo -i=10 yeah" eval %tmp # Rebind the command to the #linux channel to get the user list eval -r=$channel(#linux) "%Nicks[]=$chan.array;" # A nice alias that allows iterating commands through all the consoles # This is by LatinSuD :) alias(iterate) { %ctxt[]=$window.list(console,all) for(%i=0;%i<%ctxt[]#;%i++) { eval -r=%ctxt[%i] $0- } } iterate echo Hi ppl! :) # A little bit shorter (but less "colorful") version might be... alias(iterate) { foreach(%x,$window.list(console,all)) eval -r=%x $0-; } iterate echo Hi again! # Evaluate a command block eval "{ echo First command!; echo Second command!; }" | ||||
See also |
||||
$escape |