Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command-line parameters in Shell Script?

Tags:

bash

shell

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?

like image 706
Dan Rosenstark Avatar asked Dec 22 '22 05:12

Dan Rosenstark


1 Answers

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'
like image 146
ghostdog74 Avatar answered Jan 03 '23 04:01

ghostdog74