tup
tup copied to clipboard
When using bash `$()` command substitution doesn't work but backticks do
Using tup 0.7.5 on ubuntu, I can't seem to get bash command substitution using $()
to work while back ticks work correctly. When
$ ls -l
total 4
-rw-rw-r-- 1 ubuntu ubuntu 105 Jun 10 23:42 Tupfile
$ cat Tupfile
: |> ^b^ echo `cat Tupfile` > %o |> Tupfile.backup
: |> ^b^ echo $(cat Tupfile) > %o |> Tupfile.backup2
$ tup
[ tup ] [0.000s] Scanning filesystem...
tup warning: generated file 'Tupfile.backup' was deleted outside of tup. This file may be re-created on the next update.
tup warning: generated file 'Tupfile.backup2' was deleted outside of tup. This file may be re-created on the next update.
[ tup ] [0.005s] Reading in new environment variables...
[ tup ] [0.005s] No Tupfiles to parse.
[ tup ] [0.005s] No files to delete.
[ tup ] [0.005s] Executing Commands...
1) [0.033s] echo `cat Tupfile` > Tupfile.backup
2) [0.033s] echo > Tupfile.backup2
[ ] 100%
[ tup ] [0.046s] Updated.
The $()
command substitution in the rule body appears to be evaluated to an empty string even before it's passed to bash.
I'm definitely using bash and bash definitely supports this syntax.
$ echo $(cat Tupfile)
: |> ^b^ echo `cat Tupfile` > %o |> Tupfile.backup : |> ^b^ echo $(cat Tupfile) > %o |> Tupfile.backup2
$ echo $SHELL
/bin/bash
I checked and it looks like /usr/bin/env bash
should be returning the right shell version as well.
The $ character is used for variables in the Tupfile, so you need to escape it if you want it to be present in the actual command string. Eg:
: |> ^b^ echo \$(cat Tupfile) > %o |> Tupfile.backup2
Is that the same as the original rule?
How do I escape a character? I looked through the man page and I didn't see any mention of escaping. I tried $$
like Make but that didn't work.
Oops, the escape sequence uses a backslash, but that got eaten by the markup or whatever. I've updated the previous comment to put it in a code section so you can see the backslash. Hope that helps!
Cool thanks, that works! Is this worth updating the docs for? Is the man page tup.1? I'm not sure where http://gittup.org/tup/manual.html ends up coming from. Is it generated from man page?