I refered this
https://unix.stackexchange.com/questions/251388/prefix-and-suffix-strings-to-each-output-line-from-command
to add prefix to output of ls
.
I want to store this output of ls
:
file1
file2
file3
in to a variable with value:
/../file1 /../file2 /../file3
This is my .sh
file:
PREFIX="/../"
OUTPUT_INLINE=$(ls | tr "\n" " ")
OUTPUT="${OUTPUT_INLINE}" | sed "s|\<|$PREFIX|g"
echo "${OUTPUT_INLINE}"
echo "${OUTPUT}"
Output is:
file1 file2 file3
It means variable OUTPUT
contains nothing.
Even if I do:
echo "${OUTPUT_INLINE}" | sed "s|\<|$PREFIX|g"
I will get:
/../file1 /../file2 /../file3
What is wrong here ?