Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

Doing this in bash, makes SUFFIX variable holding /dev/fd/[fd],

SUFFIX=<( echo "&*645\[]}#@name" | sed -r 's/[^[:alnum:]]+/_/g' )

What should I do to assign the actual result, of commands being executed in between parenthesis? So in this case SUFFIX should be assigned a value of _645_name?

share|improve this question
up vote 7 down vote accepted

You've used the syntax for process substitution, which passes the output of a command as input to another command. But what you wanted was command substitution, which grabs the output of a command as a string. Command substitution uses $(…).

SUFFIX=$( echo "&*645\[]}#@name" | sed -r 's/[^[:alnum:]]+/_/g' )

Note that if you're using bash, you can do this with its own built-in constructs. If the text to sanitize is in the variable foo:

shopt -s extglob
share|improve this answer
Great! I was just about to ask for a builtin equivalent of doing the same thing, which of course is much more efficient and less dependent on other external commands. Thanks. – branquito Mar 22 '14 at 0:30
Please see my edit. – branquito Mar 22 '14 at 0:48
@branquito That's a completely different question. Please don't ask unrelated questions together. (But to save you a trip, the answer is "outfile-" ENVIRON["SUFFIX"] ".txt" — there's no interpolation in awk strings, but juxtaposition is concatenation.) – Gilles Mar 22 '14 at 0:52

If that's your suffix the answer should be this easy:


To get the pieces with this method you can at most ever get head and tail. But you can get those:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.