Reputation: 45
I have a script that is to create a config. file and input some lines into it. But when I run the script, I get the error message:
line 2: filebeat.inputs:
- type: filestream
id: my-filestream-id
enabled: true
: bad substitution
Any idea what this means? and how i can fix it? I have shared the script below:
#!/bin/bash
cat > "config.yml" <<EOF
filebeat.inputs:
- type: filestream
id: my-filestream-id
enabled: true
paths:
- /home/ubuntu/logs/**/*.log
filebeat.config.modules:
# Glob pattern for configuration loading
path: ${path.config}/modules.d/*.yml
reload.enabled: false
setup.template.settings:
index.number_of_shards: 1
setup.kibana:
output.logstash:
hosts: ["10.09.0.2:5044"]
processors:
- add_host_metadata:
when.not.contains.tags: forwarded
- add_cloud_metadata: ~
- add_docker_metadata: ~
- add_kubernetes_metadata: ~
EOF
Upvotes: 0
Views: 871
Reputation: 207
Adding a backslash before the $
avoids this problem:
#!/bin/bash
if [ ! -f config.yml ]
then
cat > config.yml <<EOF
printf "filebeat.inputs:
- type: filestream
id: my-filestream-id
enabled: true
paths:
- /home/ubuntu/logs/**/*.log
filebeat.config.modules:
# Glob pattern for configuration loading
path: \${path.config}/modules.d/*.yml
reload.enabled: false
setup.template.settings:
index.number_of_shards: 1
setup.kibana:
output.logstash:
hosts: [\"10.09.0.2:5044\"]
processors:
- add_host_metadata:
when.not.contains.tags: forwarded
- add_cloud_metadata: ~
- add_docker_metadata: ~
- add_kubernetes_metadata: ~"
EOF
fi
ls -ltr config.yml
Read more at: Bash - difference between <<EOF and <<'EOF' Assume that I am having following task:
printf "\$PATH"
instead of using
printf "$PATH"
Sample command:
$ echo -e "#\041/bin/bash\necho \$PATH" > test.sh;cat test.sh
#!/bin/bash
echo $PATH
$ chmod +x ./test.sh
$ ./test.sh
/usr/bin:/bin:....output
Hence I used $ I tried using printf you can use
Upvotes: -3