Bash tool fails with command substitution syntax $(...)

Resolved 💬 3 comments Opened Nov 13, 2025 by maximeantoine1997 Closed Nov 17, 2025

Description

The Bash tool fails to execute commands that contain command substitution using the $() syntax. The shell appears to be interpreting the syntax incorrectly, resulting in parse errors.

Example Commands That Fail

  1. Basic command substitution:
docker run --rm $(docker build --target wheel-builder -f Dockerfile.consolidated . --quiet) ls /root/.cache/uv/
  1. With intermediate variable:
IMAGE_ID=$(docker build --target wheel-builder -f Dockerfile.consolidated . --quiet) && docker run --rm $IMAGE_ID cat /wheels/deps/metrics.txt
  1. Nested in other commands:
docker run --rm $(cat /tmp/image.txt) ls -la /root/.cache/uv/

Error Message

/opt/homebrew/bin/bash: eval: line 1: syntax error near unexpected token `('
/opt/homebrew/bin/bash: eval: line 1: `docker run --rm \$ ( docker build ... ) cat /wheels/deps/metrics.txt < /dev/null | head -20'

Notice that the $() is being split into \$ ( with spaces, suggesting the parentheses are being escaped or parsed incorrectly.

Workaround

The current workaround is to write the command substitution result to a temporary file first:

docker build --target wheel-builder -f Dockerfile.consolidated . --quiet > /tmp/image.txt
docker run --rm $(cat /tmp/image.txt) ls -la /root/.cache/uv/

However, this still fails with the same error when using $(cat /tmp/image.txt).

An alternative workaround is to use xargs:

docker build --quiet | xargs -I {} docker run --rm {} ls /root/

Expected Behavior

The Bash tool should handle command substitution syntax $() correctly, executing the inner command and substituting its output into the outer command.

Environment

  • Model: Claude Sonnet 4.5 (claude-sonnet-4-5-20250929)
  • Platform: darwin (macOS)
  • Shell: /opt/homebrew/bin/bash

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗