I'm trying to simplify switching between KANBANFILE
's using kanban.bash on Windows.
I'm using several aliases such as the following for switching between KANBANFILE
s:
alias k.pos="export KANBANFILE=\"/c/Users/ajleer/OneDrive - Name Of SomeOneDrive/kanbandb/.kanban.pos.csv\""
but the following line breaks it in two different places with an ambigious redirect error which means that the file it's trying to read from isn't there:
update_item_status(){
item="$( cat "${KANBANFILE}" | awk "{ if (NR==$1) print \$0 }" )"
[[ ${#item} == 0 ]] && echo "item $1 not found" && exit 1
if [[ -n "$2" ]]; then # status change
status="$(echo "$item" | awk -F',' '{ print $1 }' | sed 's/"//g' )"
flags="$(echo "$item" | awk -F',' '{ print $4 }' | sed 's/"//g' )"
dates="$(echo "$item" | awk -F',' '{ print $5 }' | sed 's/"//g' )"
newflags="$flags${2:0:1}"
newdates="$dates $(get_current_date)"
[[ "$2" =~ "DONE" ]] && date="$(get_current_date)"
newitem="$item"
newitem="${newitem/$status/$2}"
newitem="${newitem/$flags/$newflags}"
newitem="${newitem/$dates/$newdates}"
KANBANITEMS="$(<$KANBANFILE)" # THE AMBIGUOUS REDIRECT Error Line
echo "${KANBANITEMS//"$item"/"$newitem"}" > "${KANBANFILE}"
echo "$status -> $2"
fi
}
and also here:
update_item(){
item="$( cat "${KANBANFILE}" | awk "{ if (NR==$1) print \$0 }" )"
[[ ${#item} == 0 ]] && echo "item $1 not found" && exit 1
status="$(echo "$item" | awk -F',' '{ print $1 }')"
echo '#
# STATUSES ARE: '${statuses[*]}'
#
'"$item" > "${TMP}".update
${EDITOR} "${TMP}".update
KANBANITEMS="$(<$KANBANFILE)" # THE AMBIGUOUS REDIRECT Error Line
newitem="$(cat "${TMP}".update | tail -n1 )"
echo "${KANBANITEMS//"$item"/"$newitem"}" > "${KANBANFILE}"
echo "updated item $1"
}
So how do I rewrite my KABANFILE export alias so that it doesn't break the code above, but so that I still can have spaces in the path pointing to the .kanban.xxx.csv
file?
The Ambigious Redirect
occurs anytime I use the kanban <task-id>
or kanban <task-id> <status>
command (even though that's really just editing the csv file with the default editor).
P.S. I am using git-bash on Windows aka MINGW64
$KANBANFILE
in those lines, like you have quoted elsewhere? – muru Jul 24 '19 at 11:49set -x
to show what your script does. You might see what's wrong with the problematic line. – Bodo Jul 24 '19 at 11:55KANBANITEMS="$(<\"$KANBANFILE\")"
it didn't fix the issue, unless the quotes are inside the variable too and that's somehow throwing it off.. – leeand00 Jul 24 '19 at 14:01set -x
to be run from inside the script? – leeand00 Jul 24 '19 at 14:01KANBANITEMS="$(<"$KANBANFILE")"
– muru Jul 24 '19 at 14:13set -x
, then runupdate_item_status
orupdate_item
to see what is causing the error – Bodo Jul 25 '19 at 07:13