Skip to content
Advertisement

Shell script ‘read’ doesnt work with ‘EOF’

This script below is working, I want to read a value from files svc1.data and used it in syntax.

administrator@dev-91:~$ while read -r name port ignored; do echo $name $port ; done <svc1.data
bendita-nussa 4003

But this script below doesn’t work, it keeps saying : -bash: syntax error near unexpected token `;’

administrator@dev-91:~$ while read -r name port ignored; do
kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: $name
  namespace: nussa
spec:
  hosts:
    - $name.nussa.svc.cluster.local
  http:
    - route:
        - destination:
            host: $name
            port:
              number: $port
            subset: v1
; done <svc1.data

Please help, whats wrong with the 2nd script..

Advertisement

Answer

Just close the HEREDOC, like this:

while read -r name port ignored; do
kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: $name
  namespace: nussa
spec:
  hosts:
    - $name.nussa.svc.cluster.local
  http:
    - route:
        - destination:
            host: $name
            port:
              number: $port
            subset: v1
EOF
done <svc1.data
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement