Shellscript Memo

Shellscript #

Double quotes #

Use double quotes when you want to apply line breaks #

#! /bin/bash

LINES=`cat <<EOF
apple
banana
lemon
EOF
`

echo ${LINES}
# apple banana lemon


echo "${LINES}"
# apple
# banana
# lemon

Don not use double quotes when using for clause #

#! /bin/bash

LINES=`cat <<EOF
apple
banana
lemon
EOF
`


COUNT=0
for i in ${LINES}
do
  echo ${COUNT}':'${i}
  COUNT=$(( COUNT + 1 ))
done
# 0:apple
# 1:banana
# 2:lemon


COUNT=0
for i in "${LINES}"
do
  echo ${COUNT}':'${i}
  COUNT=$(( COUNT + 1 ))
done
# 0:apple banana lemon

References #