# The following is not safe:

var=$(dirname "${f}")

# The solution to this problem is very simple: add a safety character after the
# last newline, then use the shell’s parameter substitution to remove the
# safety character:

var=$(
  command
  echo x
)
var=${var%?}

# In the case of the dirname command, one also wants to remove the single final
# newline added by dirname, i.e.

var=$(
  dirname "${f}"
  echo x
)
var=${var%??}

# Of course there is an easier way to get the directory part of a pathname,
# provided you don’t care about some of the odd corner-case semantics of the
# dirname command:

var=${f%/*}
