Lost with this alias why it is not working

Hi,

I have the following aliases:

$: alias | grep "^du="
du='du -s * 2>/dev/null | awk '\''{ printf "%4.2f-KB ==> %s \n", $1/1024 , $2 }'\'' | sort -rn'
$: alias | grep "^dutop10="
dutop10='du -s * 2>/dev/null | awk '\''{ printf "%4.2f-KB ==> %s \n", $1/1024 , $2 }'\'' | sort -rn | head -10'

du is working like I expect it to be but dutop10 isn't and I can't figure out what's wrong.

Runtime example running du as below:

$: du
0.02-KB ==> test13
0.01-KB ==> test9
0.01-KB ==> test8
0.01-KB ==> test7
0.01-KB ==> test6
0.01-KB ==> test5
0.01-KB ==> test4
0.01-KB ==> test3
0.01-KB ==> test2
0.01-KB ==> test15
0.01-KB ==> test14
0.01-KB ==> test12
0.01-KB ==> test11
0.01-KB ==> test10
0.01-KB ==> test1

Runtime example running dutop10 as below:

$: dutop10
[7] +  Done                    dutop10

Yes, that's all it has, not sure what's Done is it referring to :frowning:
But running the alias du | head -10 works fine below.

$: du | head -10
0.02-KB ==> test13
0.01-KB ==> test9
0.01-KB ==> test8
0.01-KB ==> test7
0.01-KB ==> test6
0.01-KB ==> test5
0.01-KB ==> test4
0.01-KB ==> test3
0.01-KB ==> test2
0.01-KB ==> test15
$: uname -a
SunOS <hostname> 5.9 Generic_122300-62 sun4u sparc SUNW,Ultra-80

What am I doing wrong?

Please post the details of your shell when posting questions like this.

What is your shell and version?

Please get in the habit of posting the details of your operating environment, shell, etc. That way, it is much easier to help you.

PS: Thanks for posting your OS :slight_smile: ... now please post the details of your shell AND OS. :slight_smile:

Hi,

On Solaris 9 this probably should work too (depending on the shell which you did not specify), try:

alias dutop10='\du -s * 2>/dev/null | awk '\''{ printf "%4.2f-KB ==> %s \n", $1/1024 , $2 }'\'' | sort -rn | head -10'

The added backslash forces the alias to use the actual command du instead of the alias du you created earlier.

An alternative you could try is to call the previously defined alias du :

alias dutop10='du | head -10' 
2 Likes