I'm trying to run a program called aldy on several .json files with a list of items (A, B, C, D)
I want to use the file name without the extension
like bob in bob.json, amy in amy.json
The desired output would be
bob.a.txt, bob.b.txt, ...
amy.a.txt, amy.b.txt, ...
The code I have
#!/usr/bin/env bash
LIST=('A' 'B' 'C' 'D')
for file in *.json; do
filename=${file%%.*}
for i in "${LIST}"; do
outfile = $filename + ".${i}.txt"
aldy -g ${i} -o $outfile $file
done
done
However, I got error message and I don't really know how to fix this.
syntax error: unexpected end of file
Any help would be greatly appreciated
Thanks in advance.
Make the following corrections:
for i in "${LIST[@]}"; do
. That's how you get all elements of an array.outfile=${filename}.${i}.txt
.- There may be no spaces around
=
in assignments. - Concatenating variables is done by placing them next to one another. You can use braces (as in
${expandthis}butnotthis
) to delimit them, but in your case simply$filename.$i.txt
would do (.
serves as delimiter).
- There may be no spaces around
aldy -g "$i" -o "$outfile" "$file"
. Quote your variables when expanding them. If you always do it, either the quotes will be redundant, or (in most cases) they will prevent problems caused by word splitting and globbing.