Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

linux set multiline variable

# in a bash script the following works:

#!/bin/sh

text="this is line one
this is line two
this is line three"
echo -e $text > filename

# alternatively:
text="this is line one
this is line two
this is line three"
echo "$text" > filename

# cat filename gives:
this is line one
this is line two
this is line three
Comment

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
Comment

linux set multiline variable

read -r -d '' my_variable << 
_______________________________________________________________________________

String1
String2
String3
...
StringN
_______________________________________________________________________________
Comment

linux set multiline variable

echo | tee /tmp/pipetest << EndOfMessage
This is line 1.
This is line 2.
Line 3.
EndOfMessage
Comment

linux set multiline variable

# If you're trying to get the string into a variable, another easy way is something like this:

USAGE=$(cat <<-END
    This is line one.
    This is line two.
    This is line three.
END
)

#If you indent your string with tabs (i.e., '	'), the indentation will be stripped out. If you indent with spaces, the indentation will be left in.

#NOTE: It is significant that the last closing parenthesis is on another line. The END text must appear on a line by itself.
Comment

PREVIOUS NEXT
Code Example
Shell :: how to warp files in linux 
Shell :: npm ERR! Command failed: git clone --depth=1 -q -b 1.3.8 git://github.com/eligrey/FileSaver.js.git 
Shell :: Deploy all file and subfolder git cpanel 
Shell :: tmux set color 
Shell :: install angular cli specific version 
Shell :: rename laravel project 
Shell :: linux find file recursively 
Shell :: npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: react-template@0.1.0 npm ERR! Found: react@18.0.0 
Shell :: convert biom to tsv 
Shell :: get all the branch in git 
Shell :: how to change time on kali linux 
Shell :: how to access docker container bash 
Shell :: shopify theme kit for linux 
Shell :: add-apt-repository 
Shell :: node js nodemailer Error: Invalid login: 535-5.7.8 Username and Password not accepted. 
Shell :: gitlab default password 
Shell :: how to remove git hooks 
Shell :: linux command after create folder cd it 
Shell :: osx copy output to clipboard terminal 
Shell :: git pull master into branch 
Shell :: find unused files android studio 
Shell :: delete folder from github repository 
Shell :: binding a mac to AD terminal 
Shell :: start apache server in ubuntu 
Shell :: error: cannot list snaps: cannot communicate with server: Get "http://localhost/v2/snaps": dial unix /run/snapd.socket: connect: no such file or directory 
Shell :: apache2 change directory root 
Shell :: how to store float values in shell script 
Shell :: linux terminal check available wifi networks 
Shell :: lua reverse shell 
Shell :: git clean 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =