Skip to content

Fix backtick evaluation in add-script and run-script inline scripts#263

Merged
sebst merged 3 commits intomainfrom
copilot/fix-backticks-in-add-script-run-script
Mar 31, 2026
Merged

Fix backtick evaluation in add-script and run-script inline scripts#263
sebst merged 3 commits intomainfrom
copilot/fix-backticks-in-add-script-run-script

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

The devcontainer CLI generates devcontainer-features.env with option values in double quotes (SCRIPT="echo \date`"). When the wrapper sources this file via . ./devcontainer-features.env, bash command-substitutes backticks before install.sh` ever runs — so the script content is already corrupted.

Fix

Re-read SCRIPT verbatim from devcontainer-features.env using awk at the top of install() in both features, bypassing shell evaluation entirely:

if [ -f ./devcontainer-features.env ]; then
    SCRIPT=$(awk '/^SCRIPT="/{sub(/^SCRIPT="/,"");v=$0;f=1;next}f{v=v"\n"$0}END{if(f){sub(/"$/,"",v);printf"%s",v}}' ./devcontainer-features.env)
fi

Without this fix: SCRIPT="echo \hostname`"SCRIPT=echo myhost With this fix:SCRIPTretains the literal `` echohostname` ``

Tests

  • add-script: new test-backtick scenario writes a script containing `hostname` and asserts the file contains the literal backtick syntax
  • run-script: new test-backtick scenario runs echo backtick_test=`hostname` and asserts the substitution actually executed (non-empty value written to output file)

Versions

Both features bumped 1.0.01.1.0.

Copilot AI linked an issue Mar 31, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix backtick handling in add-script and run-script Fix backtick evaluation in add-script and run-script inline scripts Mar 31, 2026
Copilot AI requested a review from sebst March 31, 2026 09:51
@sebst sebst marked this pull request as ready for review March 31, 2026 09:56
Copy link
Copy Markdown
Member

@sebst sebst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One test fails

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

One test fails

Fixed in c2ea83f. The run-script scenario test was failing with tmpScript: unbound variable — the EXIT trap (trap 'rm -f "${tmpScript}"' EXIT) fired after install() returned, but tmpScript was declared with local so it was out of scope when the trap ran. Removing local makes it a global variable that the EXIT trap can access.

Copilot AI requested a review from sebst March 31, 2026 10:25
@sebst sebst merged commit c575a44 into main Mar 31, 2026
11 checks passed
@sebst sebst deleted the copilot/fix-backticks-in-add-script-run-script branch March 31, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backticks in add-script and run-script

2 participants