Should the extension be stripped in $2 of file.a.b.do?

55 views
Skip to first unread message

mle...@gmail.com

unread,
Oct 8, 2019, 4:54:15 AM10/8/19
to redo
Hi!


The three arguments passed to the .do script are:

  • $1: the target name (eg. mytarget.a.b)
  • $2: the basename of the target, minus its extension (eg. mytarget)
  • $3: a temporary filename that the .do script should write its output to.
 
However, this is not always what I get. If I have a do file whose name does not start with "default...", I observe a different behaviour, the extension is not stripped

file        do-file           $2
----------- ----------------  ----------
file
.a.b.c  file.a.b.c.do     file.a.b.c
file
.a.b.c  default.a.b.c.do  file
file
.a.b.c  default.b.c.do    file.a
file
.a.b.c  default.c.do      file.a.b
file
.a.b.c  default.do        file.a.b.c

Below this mail is example code to test this. I don't see the reason for this behaviour. Is it a bug or a feature? Should the documentation be updated?

Best,
Moritz

Example:


cat
>default.do <<EOF
echo
"\$0" "\$2" >&2
EOF
redo file.a.b.c

mv
default.do default.c.do
redo file.a.b.c

mv
default.c.do default.b.c.do
redo file.a.b.c

mv
default.b.c.do default.a.b.c.do
redo file.a.b.c

mv
default.a.b.c.do file.a.b.c.do
redo file.a.b.c


rm file
.a.b.c.do


Wolfgang Faust

unread,
Jan 7, 2022, 1:01:12 AM1/7/22
to redo
I suspect this behavior is because, with a target that matches the entire filename, redo does not know which part of the filename to consider the extension. For example, when I run "redo example.com.meta.json.gz", redo finds "default.meta.json.gz.do" and passes it "$2=example.com" (so that I can write "$2.info.txt" and get the corresponding file). But without the context provided by the .do file, it's ambiguous which parts of that filename are "the basename" and which parts are extensions. I could, for example, also have a "default.gz.do", and if redo matched that it would set "$2=example.com.meta.json" instead, so I could write `gzip -c "$2" > "$3"` and achieve the desired result.

That said, I agree that the documentation here is lacking on details. I've also found myself confused on the expected behavior of $2 when the .do file is in a different directory from the target—the manual explains what happens in this situation to $1 and $3, but unfortunately makes no mention of $2.

spacefro...@meterriblecrew.net

unread,
Jan 7, 2022, 7:03:16 AM1/7/22
to redo...@googlegroups.com
The behaviour is exactly as specified.

Look at default.do as follows:
- the string 'default' means wildcard
- the suffix .do is not part of the match
- any string starting with a . (dot) is a legal suffix to the string 'default'

The suffix is stripped from $2. It becomes clear now, that in default.do, that suffix is the empty string. So, nothing gets stripped.

Kind regard,
–Michael
Reply all
Reply to author
Forward
0 new messages