Reputation: 69747
I am trying to include this
du -s *|awk '{ if ($1 > 3000) print }'
in a shell script, but I want to parameterize the 3000. However, since the $1
is already being used, I'm not sure what to do. This was a total failure:
size=$1
du -s *|awk '{ if ($1 > $size) print }'
How can I pass a parameter in place of 3000 in the first script above?
Upvotes: 4
Views: 850
Reputation: 67831
You can set awk
variables on its command line:
du -s * | awk '{ if ($1 > threshold) print }' threshold=$1
Upvotes: 1
Reputation: 342273
when passing shell variables to awk, try to use the -v
option of awk as much as possible. This will be "cleaner" than having quotes all around
size="$1"
du -s *| awk -v size="$size" '$1>size'
Upvotes: 4
Reputation: 798456
Single quotes inhibit expansion, so:
du -s *|awk '{ if ($1 > '"$1"') print }'
Upvotes: 3