0

This is the size of a directory

casper@casperbox$ du -sh /home/casper/
28G     /home/casper

I have a script that checks the size of the directory.

#!/bin/bash
SIZEOFdir="/home/casper/"
humanReadSizeonly=$(du -sh $SIZEOFdir | awk '{print $1}')

Instead of using awk in this context, as I always do, what is the pure bash non awk way of getting just the 28G ? And I don't want to use cut. There is some bash function in bash, and I really don't know what its name is.

I use this to get rid of .sh or .pl from filenames.

${var%.*} 

I just do not know what the method is called.

capser
  • 2,442
  • 5
  • 42
  • 74
  • This is called parameter expansion - https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html – Josh Jolly Jan 16 '18 at 23:28
  • See [the bash-hackers' wiki page on parameter expansion](http://wiki.bash-hackers.org/syntax/pe), and [BashFAQ #100](http://mywiki.wooledge.org/BashFAQ/100) (*How do I do string manipulations in bash?*) – Charles Duffy Jan 16 '18 at 23:30
  • `${var%%[[:blank:]]*}`. Check the link posted in @CharlesDuffy's [comment](https://stackoverflow.com/questions/48291428/pure-bash-cutting-strings#comment83567986_48291428). That is one of the best tutorials on parameter expansion. – PesaThe Jan 16 '18 at 23:31

0 Answers0