Reputation: 320
I have a bash function as follows:
function folderSize{
du -hs | awk '{print $1}'
}
folderSize
When I run it I get the following error:
./size.sh: line 2: syntax error near unexpected token `du' ./size.sh:
line 2: ` du -hs | awk "{print $1}"'
Can any one help me?
Upvotes: 1
Views: 186
Reputation: 3884
function folderSize {
du -hs $1 | awk '{print $1}'
}
folderSize '.'
Upvotes: 0
Reputation: 21851
I'm not sure if syntax of your variant is correct. I usually do it somewhat like this:
folderSize() {
du -hs | awk '{print $1}'
}
folderSize
Upvotes: 0
Reputation: 95385
space is required before the {.
function folderSize {
du -hs | awk '{print $1}'
}
Also, the way you call the function is just folderSize
, no dollar sign, no parentheses.
Upvotes: 5