Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

$(cat <

1. Assign multi-line string to a shell variable
$ sql=$(cat <<EOF
SELECT foo, bar FROM db
WHERE foo='baz'
EOF
)
The $sql variable now holds the new-line characters too. You can verify with echo -e "$sql".

2. Pass multi-line string to a file in Bash
$ cat <<EOF > print.sh
#!/bin/bash
echo $PWD
echo $PWD
EOF
The print.sh file now contains:

#!/bin/bash
echo $PWD
echo /home/user
3. Pass multi-line string to a pipe in Bash
$ cat <<EOF | grep 'b' | tee b.txt
foo
bar
baz
EOF
The b.txt file contains bar and baz lines. The same output is printed to stdout.

Comment

$(cat <

# Here Documents
This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen.
All of the lines read up to that point are then used as the standard input for a command.
The format of here-documents is

<<[-]word
    here-document
delimiter
Comment

$(cat <

$ cat >> test <<HERE
> Hello world HERE <-- Not by itself on a separate line -> not considered end of string
> This is a test
>  HERE <-- Leading space, so not considered end of string
> and a new line
> HERE <-- Now we have the end of the string
Comment

$(cat <

if true; then
    cat <<-EOF
    a
    EOF
fi
Comment

$(cat <

cat <<-EOF
<tab>a
<tab>EOF
Comment

PREVIOUS NEXT
Code Example
Shell :: shell script call another script with parameters 
Shell :: alternative echo linux 
Shell :: set 
Shell :: unity windows build support failed to install arch linux 
Shell :: Jenkins-SonarQube 
Shell :: maingit-branch--m-main-<BRANCH-git-fetch-origin-git-branch--u-origin/<BRANCH-<BRANCH-git-remote-set-head-origin--a 
Shell :: git hyj 
Shell :: Set Up Imagick 
Shell :: error: home_manuelschneid3r_Arch: key "" is unknown 
Shell :: This script uses variables to make a backup of my home directory. 
Shell :: Powershell mount disk image and retrieve drive-letter 
Shell :: iptables linux 80 and 443 open 
Shell :: pipeline structural bioinformatics 
Shell :: The default branch has been renamed 
Shell :: tapping home-brew/core 
Shell :: how to change line in slack 
Shell :: rar command line split size 
Shell :: how to chang spark hadoop replication factor on commandline 
Shell :: openssl rand -hex 32 windows 
Shell :: Auto-open DevTools on every new tab For cmd on Windows 
Shell :: how to merge two repositories in github 
Shell :: To install latest version of something with pip in python 
Shell :: changed files git 
Shell :: vagrant download 
Shell :: change date and time in kali linux 2021 
Shell :: brew install rosetta 
Shell :: how to uninstall photos app in windows 10 
Shell :: vscodium download ubuntu 
Shell :: tkPDFViewer install 
Shell :: awk select second field stored in a variable 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =