Alias or Environment Variable -- is one better?

Dec 26, 2009
36
2
No where
In a batch file, I can do this:

alias wrar = "C:\Program Files\WinRAR\Rar.exe" a -r -idcdp -m5 -rr10
Then when I want to create a RAR archive I can just do:
wrar archivename

I can also do this:
set wrar = "C:\Program Files\WinRAR\Rar.exe" a -r -idcdp -m5 -rr10
And then create a RAR archive with:
%wrar archivename

I've done it both ways and they both work. Is one better or preferable to the other?
 

samintz

Scott Mintz
May 20, 2008
1,557
26
Solon, OH, USA
In your example I think they both do the same thing. There might be slightly different parsing paths taken.
 
May 20, 2008
12,176
133
Syracuse, NY, USA
Environment variables don't take parameters as aliases do ... show-stopper! Below, "divide" is an alias. I imagine that would be hard to do using an environment variable.

Code:
v:\> divide 6 by 4
1.5

v:\> divide 6 by
You dummy!

v:\> divide 6 bye 4
You dummy!

v:\> divide 7 by 2
3.5

And environment variables are inherited by external apps; aliases are not. Rar.exe (or any other program you might run) doesn't need to know that "wrar" means.
 
Nov 2, 2008
246
2
I use a rexx script to create .zip and .rar files. This basically creates a blank file, that can be opened in anything, such as fc/2 or wincmd. It just creates an empty zip file.

The ,ION is a fix for some programs putting quotes around the file name, and others not reading them as a result. Basically, it removes the quotes.

Code:
/**/
parse arg filename .
parse upper var filename . '.' ext
select
  when ext = 'RAR' then call newrar
  when ext = 'ZIP' then call newzip
  when ext = 'ION' then call fixion
  otherwise; nop;
  end
exit


newrar:
rartxt = '52617221 1a0700cf 90730000 0d000000 00000000'x
call stream filename, 'c', 'open write replace'
call charout filename, rartxt
call stream filename, 'c', 'close'
return


newzip:
ziptxt = '504B0506  00000000 00000000 00000000 00000000 0000'x
call stream filename, 'c', 'open write replace'
call charout filename, ziptxt
call stream filename, 'c', 'close'
return


fixion:
'gsar.exe descript.ion -o -s":034" -r""'
return
 
Aug 23, 2010
688
9
Just
Code:
set RAR=-r -idcdp -m5 -rr10
in your user (or system, but beware!) environment block.
RAR will read default options from this env.var.

Mine is set to
Code:
[C:\]$ set RAR
RAR=-m5 -mdE -mm -s -w"C:\Windows\TEMP" -idp -os
 

Similar threads