1

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 KANBANFILEs:

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

9
  • 1
    Why didn't you quote $KANBANFILE in those lines, like you have quoted elsewhere?
    – muru
    Commented Jul 24, 2019 at 11:49
  • Use set -x to show what your script does. You might see what's wrong with the problematic line.
    – Bodo
    Commented Jul 24, 2019 at 11:55
  • @muru You mean in the script lines that are causing the error? I didn’t write the script. I did however notice that those are the only two lines where the ‘$KANBAN’ variable is referenced without quotes.
    – leeand00
    Commented Jul 24, 2019 at 11:57
  • Then can you edit the script? If so, fix the quoting there.
    – muru
    Commented Jul 24, 2019 at 11:58
  • 1
    @leeand00 KANBANITEMS="$(<"$KANBANFILE")"
    – muru
    Commented Jul 24, 2019 at 14:13

1 Answer 1

2

The quotes outside a command substitution are independent from the quotes inside it. So just quote "$KANBANFILE" like you do elsewhere.

$ filename="foo bar"
$ echo hello > "$filename"
$ echo "$( < $filename )"           #  $filename is not quoted
bash: $filename: ambiguous redirect

$ echo "$( < "$filename" )"         # "$filename" is quoted
hello

That said, in an assignment the outer quotes aren't strictly necessary, so var=$(something) works as well as var="$(something)" (Barring bugs).

See, e.g. Quoting within $(command substitution) in Bash and Do I need to quote command substitutions when assigning their output to a variable?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .