I currently try to figure out How exactly i can generate a Doskey Alias that allows Pipes.
I want to gather the foldersize in kB.
I have tried
alias dirsize=du -P -c -a -b $1 | grep total | awk '{print "Folder has: " $1 "kB"}'
But i simply get the Output
Folder has: kB
When I just use
dirsize=du -P -c -a -b $1 | grep total
It gets me
C:\>dirsize Temp
1364201 total
But how do I use the awk pipe now?
What am I doing wrong?
Inside a doskey alias
the pipe character is
$b
all instances of
$1
will be replaced with the first argument in the call to the alias, so, the$1
inside theawk
command will be replaced during the alias parse and at execution time it will not be a reference to the argumentThe usual solution to this problem inside a
doskey
alias is to convert the$1
into something that will not interfere the command execution but avoids doskey parser to handle it. To do it, the usual solution is to use$^1
, but in this case, this sequence is not handled bycmd
, it is handled byawk
and the^
is not considered a escape character.We need to solve it inside
awk
, replacing the direct$1
using a variable (i
) to store the index to retrieve and replacing the$1
with$i
that has no special meaning insidedoskey
aliases.