You can pass variables to your awk script directly from the command line.
Change this line:
filetime[$'$colnumber']++;
To:
filetime[colnumber]++;
And run:
ls -al | awk -f ./myawk.awk -v colnumber=5
If you really want to use a bash wrapper:
#!/bin/bash var1=$1 awk -f myawk.awk colnumber=$var1
(with the same change to the script as above.)
If you want to use environment variables, use:
#!/bin/bash export var1=$1 awk -f myawk.awk
and
filetime[ENVIRON["var1"]]++;
(I really don't understand what the purpose of your awk script is. The last part can be simplified:
END { print filetime[colnumber],colnumber; }
and parsing ls output is usually a bad idea.)
source share