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_VALUE:
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: 2 comments 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_VALUE:
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.
-
|
As of August 2025 we have fake gnu utils in DOS! You can now just use it directly on DOS some-task:
desc: "Mock Minimal Cat"
vars:
MY_VALUE:
sh: '[ -f backup.txt ] && cat backup.txt || echo "my one-ish time command"'
cmds:
- cmd: 'echo "{{.MY_VALUE}}" > backup.txt '
- cmd: 'cat backup.txt'
- cmd: 'rm -f backup.txt'You still need to do the test |
Beta Was this translation helpful? Give feedback.
As of August 2025 we have fake gnu utils in DOS!
https://taskfile.dev/blog/windows-core-utils
#2360
You can now just use it directly on DOS
You still need to do the test
[ -f backup.txt ]because fakecatfails fatally when it can't access the file.See #2466