How to preserve spaces when outputting a shell variable? [duplicate] How to preserve spaces when outputting a shell variable? [duplicate] bash bash

How to preserve spaces when outputting a shell variable? [duplicate]


Use More Quotes! echo "$jpat" will do what you want.

There is another issue with what you're doing: Command substitutions will remove trailing newlines. It's not an issue in the printf command you're using, but for example assigning jpat=$(printf " %6i\n" "$jj") would give you exactly the same result as your command.