Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

linux set multiline variable

# You may use echo:

echo    "this is line one"   
    "
""this is line two"   
    "
""this is line three" 
    > filename
#It does not work if you put "
" just before  on the end of a line.


# Alternatively, you can use printf for better portability (I happened to have a lot of problems with echo):

printf '%s
' 
    "this is line one"   
    "this is line two"   
    "this is line three" 
    > filename


# Yet another solution might be:

text=''
text="${text}this is line one
"
text="${text}this is line two
"
text="${text}this is line three
"
printf "%b" "$text" > filename


#or

text=''
text+="this is line one
"
text+="this is line two
"
text+="this is line three
"
printf "%b" "$text" > filename
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #linux #set #multiline #variable
ADD COMMENT
Topic
Name
7+6 =