[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Avoiding a shebang to call awk

From: Greg Wooledge
Subject: Re: Avoiding a shebang to call awk
Date: Tue, 21 Feb 2023 07:20:05 -0500

On Tue, Feb 21, 2023 at 07:24:23AM +0000, goncholden wrote:
> I have make an awk file named "tool.awk".  But I want to use its name 
> "tool" rather than having to call awk directly.
> Originally I had a shebang, namely "#!/bin/awk -f" in the file "tool.awk".

This is the preferred approach.  Simply rename the file from "tool.awk"
to "tool", make sure the directory in which it lives is in your PATH,
chmod +x if you haven't already, and you're all set.

> I have removed the awk shebang from the file and added a bash function
> tool ()
> {  
>   local epath="${HOME}/Opstk/bin//opcon"
>   awk -f "${epath}"/tool.awk "${@:--}"
> }

This seems like a bad idea to me.  Now, any time you want to do
maintenance work on your tool, you have to look in *two* places.  Also,
your tool can't be used by anybody but you, and then only if you start
with an interactive shell.  You can't run it from a cron job, for example,
or do something like "find . -type f -exec tool {} +".

If you really want "tool.awk" to retain that horrible name, and to live
in a directory which is not in PATH, then the third choice is to leave
it where it is, named what it is, but create a symbolic link from a
directory that's in PATH.  For example,

mkdir -p ~/bin; ln -s ~/Opstk/bin/opcon/tool.awk ~/bin/tool

Ensure $HOME/bin is in your PATH, and you should be good to go.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]