Fixes #19815
Changes interpreter to ‘bash’ since it uses ‘command_not_found_handle’
sed -i file1 -e ’s/world/WORLD/’ file2
This command will work without throwing error on both gnu and bsd sed, but will do different things.
This approach removes all commands from shell environment, adds a function that runs in place of sed and checks if the arguments are compatible. Second commit adds a check that prevents this issue. ‘sed’ function can be modified to check for any incompatibilities between sed versions.
61@@ -28,7 +62,11 @@ for commit in $(git rev-list --reverse $1); do
62 echo "Error: missing script for: $commit"
63 echo "Failed"
64 RET=1
65+ elif verify_script "$SCRIPT"; then
66+ echo ERROR: You are using BSD sed syntax for "-i" option, which is incompatible with GNU sed
67+ RET=1
68 else
69+ verify_script "$SCRIPT"
verify_script
twice when it fails (in both the elif
condition and else
branch)?
24+ (
25+ export PATH='/invalid'
26+ # ignore commands other than 'sed'
27+ function command_not_found_handle () {
28+ return 0;
29+ }
I don’t see any examples where it’d be a problem, but that won’t capture any builtin commands.
This will block processing of git ls | xargs sed
so those cases won’t be checked.
I am not convinced it is worth to add 37 lines of obscure bash that no one understands (or a regexp with similar complexity),
I tend to agree. I cannot review this at least, and very few active developers here can, so the general tendency is to keep the amount of advanced shell script in bitcoin core down. Usually in favor of Python, but maybe that’s not really an option here.
So -0 on this.