EOF


Examples of cat <<EOF syntax usage in Bash:


#!/bin/bash
docker build -t willrstern/test-node .
docker push willrstern/test-node

ssh root@162.243.27.75 << 'EOF'
    for i in `seq 1 3`
    do
      docker -H :4000 build --build-arg="affinity:container==~web$i" --pull - <<< "FROM willrstern/test-node"
      docker -H :4000 stop web$i || true
      docker -H :4000 rm web$i || true
      docker -H :4000 run -d --restart always --net apps --name web$i \
        -e constraint:type==apps \
        -e SERVICE_VIRTUAL_HOST=test.com \
        -e SERVICE_NAME=web \
        -e SERVICE_TAGS=nginx:production \
        -e SERVICE_PORT=3000 \
        willrstern/test-node
    done
EOF



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

Comments

Popular posts from this blog

HAproxy logging

tomcat catalina coyote jasper cluster

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all