alias top3 {
var %x = 1
while (%x <= 3) {
var %n = $$1
if ($isfile($+(file,%n,.txt))) echo -a $read($+(file,%n,.txt),%x)
inc %x
}
}
-Andy
alias top3 {
var %n = $$1
var %x = 1
if ($isfile($+(file,%n,.txt))) {
while (%x <= 3) {
echo -a $read($+(file,%n,.txt),%x)
inc %x
}
}
}
The minor modificatin means that you only need to check for the existence of the file once.
alias top3 {
var %fname = $+(file,$1,.txt)
var %x = 1
if ($isfile(%fname)) {
while (%x <= 3) {
echo -a $read(%fname,%x)
inc %x
}
}
}
I would go the next step (listed above), for readability. The use of '$$' in the original codehas no effect, as you use %n reardless of whether theere was anything in $1 or not. This version (above) will look in a default file "file.txt" if no arguments are passed. If you want there to be no file name, then use $$1 instead of $1.
or perhaps you could use the line :
if ($isfile(%fname) && $0) {
which will check to see if $0 >0 (thus the presence of arguments to the command).
not tested.
Cheers,
DK