There is another way if all you want is the text up to the first line feed:
x='some
thing'
y=${x%$'\n'*}
After that y
will contain some
and nothing else (no line feed).
What is happening here?
We perform a parameter expansion substring removal (${PARAMETER%PATTERN}
) for the shortest match up to the first ANSI C line feed ($'\n'
) and drop everything that follows (*
).