You need to remove the literal '
chars. from the line in order for the address to be passed correctly to mailx
:
There's more than one way to do it:
mailx -s "New Member" "$(tr -d "'" < ../address)"
mailx -s "New Member" "$(xargs < ../address)"
Note: The above assumes that ../address
contains only 1 line.
@chepner makes an important point:
storing the quotes in the file and then reading them in [and using the result unquoted] is not the same as quoting the command substitution.
To elaborate on this further:
The OP shows
'my-email@gmail.com'
as the desired argument to pass tomailx
. In this direct form of single-quoting, bash will remove the quotes (seeQuote Removal
section inman bash
) before handing the - unexpanded - string contents, without the quotes, tomailx
.Indirect quoting does NOT work: Reading in a string that happens to contain literal quote characters around it is NOT subject to quote removal by bash, so the enclosing quotes are passed through as part of the string -
mailx
would see an invalid email address that starts (and ends) with a'
.Therefore, the solution is:
- remove the quotes from the input string first
- then use direct quoting to protect the result from (further) shell expansion; note that double-quoting is needed so as to make sure the command substitution (
($...)
) is evaluated.