I'm trying to write a backup and restore function for automation.
I'm struggling to populate the dictionary with path information.
Here's a snippet from the backup function.
FILE="path/to/file"
BASENAME=$(basename $FILE)
key="$BASENAME"
value="$FILE"
test_dict[$key]=$value
echo ${test_dict[*]}
I get this
bash: package.json: syntax error: invalid arithmetic operator (error token is ".json")
This is my first bash script and I'm not really fussed about what storage type I'm using, be it array, dictionary, etc... all I care about is to keep track of which file belongs where.
This is my first bash script so sorry if this is a trivial question/error on my side.
I'd really appreciate your input on this.
Cheers :)
Edit: test_dict is declared with:
declare -a test_dict
CodePudding user response:
I got into all of this mess bc my shell won’t accept declare -A
, which is to declare it as associative.
running bash --version
spits out:
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin20)
Copyright (C) 2007 Free Software Foundation, Inc.
all I had to do was to update bash to the latest version. For that I used: brew update && brew install bash
Now my code works just fine.
M :)