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
$ball instances of
$1will be replaced with the first argument in the call to the alias, so, the$1inside theawkcommand 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
doskeyalias is to convert the$1into 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 byawkand the^is not considered a escape character.We need to solve it inside
awk, replacing the direct$1using a variable (i) to store the index to retrieve and replacing the$1with$ithat has no special meaning insidedoskeyaliases.