Closed nodupe closed 1 year ago
There is an error in your template.
The first line:
{{ if eq .chezmoi.os "linux" }}
#!/usr/bin/sh
includes a newline character at the end of the line, so the #!
occurs on the second line.
To fix this, instruct the template language to remove the whitespace by adding a -
before the closing }}
:
{{ if eq .chezmoi.os "linux" -}}
#!/usr/bin/sh
I've added an FAQ entry in 5568ec1e54e06b938ce8768a6497f6d5c94ec35d.
Thank you, that solved my issue and I've learned a new trick! Neat!
Describe the bug
Shebang needs to happen before the templating. I am not sure if this is an actual bug, but I'd like to point out that if I use a template file "run_once_before_test.tmpl" with this content:
I will receive a "fork/exec error".
I've realized that if I change it slightly to:
It works as intended.
To reproduce
create the file run_once_before_test.tmpl and add the content (on a linux machine):
do
Expected behavior
Run the proper script (in this case ls on the directory chezmoi runs):
Output of command with the
--verbose
flagOutput of
chezmoi doctor
Additional context
I've started using templating mainly to differentiate between windows or linux machines (also between distros sometimes). In case I am in windows a bat file should run, in linux a shell script would run. It made sense to me that the templating would add the shebang text on linux machines, and after the script would run. It is not not a real issue in my case, since bat will interpret # as a comment, and there will be no issue on the .bat execution. I can also have 2 different tmpl, one .sh and one .bat - so my usecase is "solved". I am opening the issue because it may be something worth documenting if not interestingly enough to fix.