#!/bin/bash # Read from standard input and output only the project root paths while IFS= read -r line; do project_path=$(echo "$line" | awk -F/ '{print $1"/"$2}') current_dir="$project_path" found=false # While we're within the project directory or or any of its parent directories while [ "$current_dir" != "." ]; do if [ -f "$current_dir/composer.json" ]; then echo "$current_dir" # Output only the project root path found=true break else current_dir=$(dirname "$current_dir") fi done if [ "$found" = false ]; then echo "$project_path" # Output the project path if 'composer.json' is not found fi done