4

I guess this answer from awk separator preferences already gives a hint, but I thought I'd ask explicitly:

Is there an equivalent to a .bashrc file for awk, where I could define my own library functions, which would be automatically (pre)loaded at every call to awk - and without using -f or @include at the command line?

  • 4
    Why not make awk into an alias to awk -f yourfunction or similar? – terdon Nov 27 '13 at 17:25
  • Thanks for the comment, @terdon - I simply want to avoid making new aliases, and have a set of commonly used functions be always automatically loaded... And I don't want to alias awk itself, because then I may eventually forget it has been aliased :) - and making up extra alias names is extra cognitive load... I guess I'm too used to the concept of "automatically load startup script" from e.g. bash ... Cheers! – sdaau Nov 27 '13 at 18:08
3

I believe that what you're asking for is impossible and I have 2 pieces of evidence for this:

1) The awk(1) man page doesn't have a FILES section that lists any files related to the operation of awk. Contrast that, for example, with the bash(1) man page that lists all of Bash's initialization files in a separate FILES section. Most commands whose behavior can be modified by configuration files, will name these files in their man page(s).

2) The ENVIRONMENT VARIABLES section in the awk(1) man page also doesn't mention any environment variables related to the loading of external files except for GAWK_PATH in the case of gawk, which tells it where to look for files named with the -f option.

I know this evidence isn't exactly conclusive, but barring any counterexamples, I'd say there's a very high chance you won't be able to accomplish this without using -f and/or aliasing awk as terdon suggested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.