I'm learning awk today, but I cannot succeed in having the most simple scripts to work.
#!/usr/bin/env -S awk -f
BEGIN { }
{ }
END { }
this outputs BEGIN: command not found
or even
#!/usr/bin/env -S awk -f
{}
this outputs {}: command not found
When I launch $ /usr/bin/env -S awk -f , I do have the awk executable that display its default output.
And $ awk --version says it's awk version 5.0.1 , on nixos 19.09.
I need to use /usr/bin/env, because nixos files are not following the traditionnal FHS directory hierarchy.
I suspect I'm missing something obvious but looking awk tutorials and SO questions has not given me any clue for now.
EDIT: the command line I use to launch the script
ls -l | . testawk.sh
#!-line like#!/usr/bin/awk -f? Very few Unices can handle#!-lines with more than a single argument (yours have three). – Kusalananda Jan 21 '20 at 09:56/run/current-system/sw/bin/awk. So it cannot work. – Stephane Rolland Jan 21 '20 at 09:58#!/run/current-system/sw/bin/awk -f. I don't know why theenv -Sroute does not work, or if it is supposed to work. – Kusalananda Jan 21 '20 at 09:59awk -f scriptnameon the command line? I see no reason why it fails to be honest. – Kusalananda Jan 21 '20 at 10:03#!/run/current-system/sw/bin/awk BEGIN {}it works. Same for#!/usr/bin/env awk BEGIN {}. I have no idea why it does not work either. That's puzzling. – Stephane Rolland Jan 21 '20 at 10:05~$ ./scriptname.sh? – AdminBee Jan 21 '20 at 10:07. test.shor evenls -l | . test.shand not./test.sh. – Stephane Rolland Jan 21 '20 at 10:09awkdirectly with a script without the#!line. – Stephane Rolland Jan 22 '20 at 00:21env -S(split 1st argument eg."-S foo bar"on spaces). Whether that's a good idea in general it's a different problem (env -Sis not portable), but it comes in handy sometimes. – Jan 22 '20 at 15:37