-1

I have made a bash function that calls an awk script.

edvart-fire ()
 {
  local epath="${HOME}/Opstk/bin/gungadin-1.0/opcon/edvart"
  awk ${epath}/firefly.awk "${@:--}"
 }

How can I run this bash function?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Dilna
  • 405
  • 1
  • 6
  • 2
    `edvart-fire` . – tkausl Feb 21 '23 at 00:26
  • 3
    `${epath}` should be `"$epath"`, quotes are VERY important in shell, see https://mywiki.wooledge.org/Quotes, get used to using them correctly and don't mistake `${var}` for `"$var"`. You already know how to tell awk to interpret a script file - `awk -f file`, not `awk file`, as you've used and seen in several of your questions and answers, and I just showed you how to call a bash function that calls awk in [my answer to your previous question](https://stackoverflow.com/a/75514484/1745001). So it's not clear why you're asking this question. – Ed Morton Feb 21 '23 at 00:42
  • @EdMorton Many have used `-f` in calling awk with `awk -f "$epath"/firefly.awk "${@:--}"`. Whilst you did not use the `-f` option. – Dilna Feb 21 '23 at 07:11
  • Using `awk -f "$epath"/firefly.awk "${@:--}"` seems necessary. – Dilna Feb 21 '23 at 07:35
  • @Goncho `-f` is not optional for reading a script from a file, I've never not used it in that context. You may be confusing `awk -f script_file.awk input_file` with `awk 'inline_script' input_file`. – Ed Morton Feb 21 '23 at 10:15

1 Answers1

0

Setting aside the function for a minute ... what are the various ways you would normally call awk with firefly.awk?

With these in hand you can then figure out how to call the function ...

# this:

awk -f "${epath}"/firefly.awk 

# becomes this:

edvart-fire

# this:

awk -f "${epath}"/firefly.awk file1 file2 file3

# becomes this:

edvart-fire file1 file2 file3

# this:

awk -f "${epath}"/firefly.awk -v v1=33 -v v2="abc def" file1 file2 file3

# becomes this:

edvart-fire -v v1=33 -v v2="abc def" file1 file2 file3

# this:

printf "abc\ndef\n" | awk -f "${epath}"/firefly.awk

# becomes this:

printf "abc\ndef\n" | edvart-fire

This assumes the function is first updated per comments, eg:

edvart-fire ()
{  
  local epath="${HOME}/Opstk/bin/gungadin-1.0/opcon/edvart"
  awk -f "${epath}"/firefly.awk "${@:--}"
}
markp-fuso
  • 28,790
  • 4
  • 16
  • 36