Transportable Cat? #1499
-
Is there some kind of command that works on both I needed to do some logic that boils down to: "If file exists, use it's contents, else, invoke one-ish time command to get value" Minimal mockBreaks on some-task:
desc: "Mock Minimal Cat"
vars:
MY_VLAUE:
sh: 'cat backup.txt || echo "my one-ish time command"'
cmd:
- 'echo "{{.MY_VALUE}}" > backup.txt '
- 'echo "{{.MY_VALUE}} -- command failure sim" && false'
- 'rm -f backup.txt' |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
echo $(<)
Figured it out! Becuase go-task uses mvdan/sh as it's command runner I just needed to use bashy contructs to get the file contents. My original problemSadly I cant do Needed to add a test: some-task:
desc: "Mock Minimal Cat"
vars:
MY_VLAUE:
sh: '[ -f backup.txt ] && echo "$(<backup.txt)" || echo "my one-ish time command"'
cmd:
- 'echo "{{.MY_VALUE}}" > backup.txt '
- 'echo "{{.MY_VALUE}} -- command failure sim" && false'
- 'rm -f backup.txt' |
Beta Was this translation helpful? Give feedback.
echo $(<)
echo "$(<backup.txt)"
Figured it out!
Becuase go-task uses mvdan/sh as it's command runner I just needed to use bashy contructs to get the file contents.
My original problem
Sadly I cant do
echo "$(<backup.txt)" || echo "works"
, the bashism fails in the interpreter [ :( ]Needed to add a test: