Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

thunderbird -compose "attachment='$HOME/test test.txt'" works. thunderbird -compose "attachment='$HOME/test, test.txt'" does not work and gives a file does not exist error message.

This must be because of the way Thunderbird handles command line arguments; e.g.,

thunderbird -compose "to='',attachment='~/file.txt'"

The compose arguments are separated by , and that must be why having a , in the file name breaks things. I cannot, however, think of a way to "escape" commas in the file name.


  • In Thunderbird 3+, using the protocol file:// is not required any more.


thunderbird -compose "attachment='$HOME/test test.txt'"


thunderbird -compose "attachment='file://$HOME/test test.txt'"



thunderbird -compose "attachment='$HOME/test, test.txt'"


thunderbird -compose "attachment='file://$HOME/test, test.txt'"


share|improve this question
At a guess I would suggest trying to escape \, or url encode %2C it. – Etan Reisner Jul 31 '13 at 1:24
Escaping comma (\,) does not work; it gives the same file does not exist error. The characters , and % are both legitimate in the file name so I don't think URL encoding is an option because test,test and test%2Ctest are both legitimate file names. – Omid Jul 31 '13 at 1:41
While true test%2Ctest would become test%252Ctest when url encoded. It is worth trying it (it might need the explicit file:// prefix to work I suppose but I don't know). – Etan Reisner Jul 31 '13 at 1:45
Sounds like a bug in the wrapper script. – Ignacio Vazquez-Abrams Jul 31 '13 at 3:13
up vote 0 down vote accepted

Using the idea of URL encoding the file names suggested by @Etan Reisner (in a comment to my question above), I hacked a solution which I record here for the benefit of others in the community. In the snippet below, ${filename} is the full file name (including path) to be attached.


# "A safe way to URL encode is to encode every single byte, even
# those that would've been allowed." This is done by first
# converting every byte to its 2-byte hex code using `hexdump' and
# then adding the prefix `%' to each 2-byte hex code pair using
# `sed'.
# Attribution:

filenameurlencoded=$(echo -ne "${filename}" | \
hexdump -v -e '/1 "%02x"' | \
sed 's/\(..\)/%\1/g')

filenamenopath="$(basename ${filename})"
emailbody="\"${filenamenopath}\" is attached."

# Syntax of -compose command line option: double-quotes enclose
# full comma-separated list of arguments passed to -compose,
# whereas single quotes are used to group items for the same
# argument.
# Attribution:

thunderbird -compose "subject='${emailsubject}',body='${emailbody}',attachment='${emailattachment}'"
share|improve this answer

You must log in to answer this question.

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