alias.sav not accurate

May 20, 2008
11,401
99
Syracuse, NY, USA
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.]
 
May 20, 2008
11,401
99
Syracuse, NY, USA
Here it is quite briefly. This shows the creation of the alias, that it works, and alias.sav's version of it.

1537742404780.png
 
May 20, 2008
11,401
99
Syracuse, NY, USA
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.
 
May 20, 2008
11,401
99
Syracuse, NY, USA
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.
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
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.
 
May 20, 2008
11,401
99
Syracuse, NY, USA
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.
 
May 20, 2008
11,401
99
Syracuse, NY, USA
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
Thread starter Title Forum Replies Date
rps How to? Shralias and producing history.sav, alias.sav .. Support 6
D Can alias pass parameters to for command? Support 3
Jay Sage Issue with CD_ENTER Alias Support 37
Jay Sage Issue with CD_LEAVE Alias Support 3
Jay Sage WAD Failure of Alias Command with /Z Option Support 14
R @select inside alias gives different (insanely small) window Support 7
kb6ojs ALIAS with multiple commands? Support 9
vefatica Can I alias @@Ctrl-Shift-Alt-u? Support 4
D Alias with setdos no longer works Support 21
vefatica TPIPE in an alias? Support 2
Peter Murschall TCC V26.01.3x Debugging has problems with Alias /R Support 1
Peter Murschall CMDebug 26.01.37 has problems with Alias Support 21
samintz How to? Alias or prompt? Support 1
MickeyF expand alias in cmdline with Ctrl-F in TCC Support 21
Jay Sage Directory Alias Access to FTP Servers Support 2
J Alias @@F5 hotkey Support 2
Joe Caverly Using a Directory Alias with @iniwrite fails Support 14
N multiple command alias and redirection Support 0
vefatica SETLOCAL ... ALIAS ... pipes Support 2
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2
rps How to? Alias/Command line use of *log on/off Support 2
MickeyF alias terminating before it should Support 3
JohnQSmith ALIAS /R in TCSTART.BTM Support 9
D Alias in batch file Support 3
vefatica Can't execute @ALIAS[...] Support 5
E How to? Load Alias File on Startup Support 3
I Windows 10 console does not allow alt-F4 alias to complete Support 1
MickeyF create an alias with optional parameter Support 4
nickles Alias expansion Support 7
T scrput `` in alias or function Support 2
vefatica Alias works differenltly v16 vs. v17 Support 13
B Alias with multi line definitions not assigned Support 6
jbanaszczyk Alias with space in the name Support 3
jbanaszczyk Alias for internal command Support 8
D Clear alias parameters Support 7
T Fixed multi-line alias issue Support 13
keithg1964 WAD 16.0027 Alias /rz bug Support 8
R In addition to ALIAS /Z and FUNCTION /Z, HISTORY /Z? Support 1
tmaynard How to? Control-U alias for Escape (command line editing) Support 5
C Alias ListEmptyFldrs=??? Support 4
M How to? Put logic into an alias... Support 6
G How to? v15: Can't alias Alt-Z Support 7
nikbackm v15: Problem with ALIAS in command group Support 10
vefatica WAD DO i=1 TO %# in an alias? Support 9
cgunhouse Directory Alias Issue Support 7
C CMD window size and post_exec alias ? Support 6
deleyd How to? Alias in TCMD.INI file? Support 2
M How to? Run a command (alias, actually) on a "timed" basis... Support 13
A strange error in alias Support 9
J Initialise; Alias; Extended directory search Support 2

Similar threads