I'm pretty old school, `tr` would be my utility of choice. But according to my bash manual, trailing newlines are automatically elided by the shell:

Command substitution allows the output of a command to replace the com-
       mand name.  There are two forms:

              $(command)
       or
              `command`

Bash performs the expansion by executing command and replacing the com- mand substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting. The command substitution $(cat
       file) can be replaced by the equivalent but faster $(< file).

When the old-style backquote form of substitution is used, backslash retains its literal meaning except when followed by $, `, or \. The first backquote not preceded by a backslash terminates the command sub- stitution. When using the $(command) form, all characters between the
       parentheses make up the command; none are treated specially.

Command substitutions may be nested. To nest when using the backquoted
       form, escape the inner backquotes with backslashes.

If the substitution appears within double quotes, word splitting and
       pathname expansion are not performed on the results.


On 2007-05-30, at 12:20 EDT, Henry Minsky wrote:

I have a shell script which binds a variable to the output of a program, and
there is a newline
at the end of it that I want to remove. What is the best way to do this? Is
there a bash builtin
which handles that, or should I just run it through sed?


--
Henry Minsky
Software Architect
[EMAIL PROTECTED]

Reply via email to