How to run a shell script having an awk command

How to run this manuscript (called count.sh)?

awk 'BEGIN{ x=0 ; while (x < 5) { x+=1 ; print x ; } }'

I'm attempting to run it with sh count.sh yet it is offering me a mistake.

0
2019-05-18 23:38:18
Source Share
Answers: 2

I ran you manuscript, yet I really did not get any kind of mistake (although I anticipated to)

$ cat test.awk
awk 'BEGIN{ x=0 ; while (x < 5) { x+=1 ; print x ; } }'
$ bash test.awk
1
2
3
4
5

What mistake did you get? I anticipated awk will certainly request for an input documents to procedure ; found out a new thingie

0
2019-05-19 13:46:01
Source

This is what I've provided for my very own manuscripts:

#!/usr/bin/awk -f
BEGIN{ x=0 ; while (x < 5) { x+=1 ; print x ; } }

The only downside to this strategy is that the course to Awk is tough - coded. This will certainly damage when the manuscript is exported using NFS, and also the NFS customer has actually Awk mounted in a various directory site (say, /bin/awk versus /usr/bin/awk.)

Establishing the executable approval will certainly permit you to straight call the manuscript, without needing to make use of the shell to release it (you can additionally end the.sh expansion, given that by convention manuscripts do not include them):

$ chmod +x count
$ ./count
1
2
3
4
5
0
2019-05-19 13:17:26
Source