Skip to content

#NL assoc array key assignment throwing syntax error #11

Description

@knksmith57

Cloning the repo and running $ bash sample_head.sh --help produces the following output, including a syntax error:

$ bash sample_head.sh --help
optparse.bash: line 140: #NL: syntax error: operand expected (error token is "#NL")
sample_head.sh: line 11: source: filename argument required
source: usage: source filename [arguments]
ERROR: Please provide a file

Looks like this associative array assignment is throwing the error:

local -A o=( ['#NL']='\n' ['#TB']='\t' )

Running the following BASH version:

$ bash --version
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright (C) 2007 Free Software Foundation, Inc.

Any idea how to fix this? My bash foo is pretty weak.

I see the use of #NL and #TB as placeholders for newlines and tabs (respectively), which are replaced on the lines following that assignment. It looks like the use of # as a special character is the reason for the ['#NL'] syntax in the array declaration. Not really sure how that works or how to debug this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions