Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

alias.sav not accurate

May
12,995
174
I created an alias thus:
Code:
alias tl=`(tasklist |! egrep -v "Total|processes|^^$" |! sort -f -b --key=2,2 |! tee %temp\tl.tmp & echo  ----^n  %@lines[%temp\tl.tmp] & del /q %temp\tl.tmp)`
ALIAS shows:
Code:
v:\> alias tl
(tasklist |! egrep -v "Total|processes|^$" |! sort -f -b --key=2,2 |! tee %temp\tl.tmp & echo  ----
  %@lines[%temp\tl.tmp] & del /q %temp\tl.tmp)

That's really two lines ... OK, the alias works.
But SHRALIAS.EXE saves it like this (from notepad).

1537738419678.png


It doesn't work when reloaded.

1. a newline is missing
2. two ^s need to be there (^^$) when it's loaded and the saving process seems to have done away with one of them.

[I still have the code for the saving routine that was used many years ago.]
 
Here it is quite briefly. This shows the creation of the alias, that it works, and alias.sav's version of it.

1537742404780.png
 
That's your code, not mine.
I wasn't sure of that. So now I don't fully understand what's going on. I do this:
Code:
v:\> alias tl=`(tasklist %1 |! egrep -v "Total.*processes|^^$" |! g:\gnu\sort.exe -f -b --key=2,2 & echo -----^r^n   %_npids)`
And the alias works and "ALIAS tl" shows
Code:
(tasklist %1 |! egrep -v "Total.*processes|^$" |! g:\gnu\sort.exe -f -b --key=2,2 & echo -----
   %_npids)
The "^r^n" became a newline and that seems to be the problem. The code you mentioned faithfully writes the shared memory to a file translating alias ending NULs into newlines. But now the extra newline is a problem when the alias is loaded.

Can you change things so that such an alias will work after being saved and reloaded?

Can I change the alias definition so it will work after being saved and reloaded.

I'm using a library routine instead of an alias on one computer; that's an acceptable alternative. But it seems that a lot of aliases which might work after being defined won't work after being saved and reloaded.
 
Can I change the alias definition so it will work after being saved and reloaded.
Of course.
Code:
v:\> alias tl=`(tasklist %1 |! egrep -v "Total.*processes|^^$" |! g:\gnu\sort.exe -f -b --key=2,2 & echo ----- & echo    %_npids)`

Here's the problem in a nutshell. I suspect it could almost always be worked around as above.
Code:
v:\> alias foo `echo line1^r^nline2`

v:\> foo
line1
line2

v:\> shralias
SHRALIAS loaded

v:\> shralias /u
SHRALIAS unloaded

v:\> tail /n 2 h:\ShrDump\alias.sav
foo=echo line1
line2

I still find it a little odd that "^r^n" becomes a newline when the alias is defined rather than when it's executed.

The main point of the alias is to get the processes sorted by name.
 
Escaped characters are processed *before* the alias is created. It has always worked that way, and changing it would break a few million aliases and batch files.

The only possible workaround would be to have SHRALIAS reinsert a ^n when it detects a LF in an alias. I'm going to have to think about possible side effects of doing that.
 
Escaped characters are processed *before* the alias is created. It has always worked that way, and changing it would break a few million aliases and batch files.

The only possible workaround would be to have SHRALIAS reinsert a ^n when it detects a LF in an alias. I'm going to have to think about possible side effects of doing that.
You're right, it has worked well for a long time. With a couple ways to get around it, don't waste your time on it.
 
And this works too (no surprise).
Code:
v:\> alias tl=`(tasklist %1 |! egrep -v "Total.*processes|^^$" |! g:\gnu\sort.exe -f -b --key=2,2 & echo -----^^r^^n   %_npids)`
 

Similar threads

Back
Top