Need help with "if then" in console
I need some help to write a special command in the console.
I want to call the size of files in the trash, with some suffix formating (sorry, my English sucks). This code works great :
du -sh ~/.Trash/ | awk '{print "Size of files in the trash: " $1"B" }'
I added a "B" at the end to write the size in "KB", "MB" and "GB".
However, when the trash is empty, it gives 0 BB, which is odd.
I tried something like the following code, but obviously it doesn't work :
du -sh ~/.Trash/ | awk '{print "Size of files in the trash: " if $1 > 0 then $1"B" else "0"}'
How can I define the "if then" condition so the code says, for example, 34MB and 0B, and not 34MB and 0BB ?
If I use the following code :
du -sh ~/.Trash/ | awk '{print "Size of files in the trash: " $1 }'
Then I'll get 34M and 0B, which I don't like. It must be 34MB and 0B.
I want to call the size of files in the trash, with some suffix formating (sorry, my English sucks). This code works great :
Code:
du -sh ~/.Trash/ | awk '{print "Size of files in the trash: " $1"B" }'
I added a "B" at the end to write the size in "KB", "MB" and "GB".
However, when the trash is empty, it gives 0 BB, which is odd.
I tried something like the following code, but obviously it doesn't work :
Code:
du -sh ~/.Trash/ | awk '{print "Size of files in the trash: " if $1 > 0 then $1"B" else "0"}'
How can I define the "if then" condition so the code says, for example, 34MB and 0B, and not 34MB and 0BB ?
If I use the following code :
Code:
du -sh ~/.Trash/ | awk '{print "Size of files in the trash: " $1 }'
Then I'll get 34M and 0B, which I don't like. It must be 34MB and 0B.