Skip to content

bin/log: line 44: mapfile: command not found #1440

@henrik-nordiskarum

Description

@henrik-nordiskarum

Description
Using bin/log requires mapfile that was introduced in bash v4. MacOS are still at v3 causing the bin/log command to not work

Steps To Reproduce

  1. run bin/log in MacOS

Expected Result

Actual Result
bin/log: line 44: mapfile: command not found

Workaround

#!/usr/bin/env bash

CONTAINER_LOG_PATH="/var/www/html/var/log/";

display_help() {
  echo -e "Description:
  Tail logs from the Magento var/log folder all and specific logs

Usage:
  bin/log <specific_log_files>

Arguments:
  specific_log_files  If specific_log_files are NOT provided, show all logs. Ex: bin/log system.log cache.log

Options:
  -h, --help          Display help message"
}

generate_logs_file_path() {
  local container_log_path="$1"
  shift  # This shifts the positional parameters to the left, so $2 becomes $1, $3 becomes $2, etc.
  local log_files=("$@")
  local log_file_paths=()

  for file in "${log_files[@]}"; do
    log_file_paths+=("$container_log_path$file")
  done

  echo "${log_file_paths[@]}"
}

get_all_logs_file_path() {
  local logs_location="$1"

  bin/docker-compose exec phpfpm ls -p "$logs_location" | grep -v '/$' | sed "s|^|$logs_location|"
}

if [[ $1 == "-h" || $1 == "--help" ]]; then
  display_help
elif [[ -z $1 ]]; then
  all_logs_file_path=()
  while IFS= read -r line; do
    all_logs_file_path+=("$line")
  done < <(get_all_logs_file_path "$CONTAINER_LOG_PATH")

  bin/docker-compose exec phpfpm tail -f "${all_logs_file_path[@]}"
else
  logs_file_path=()
  for file in "$@"; do
    logs_file_path+=("${CONTAINER_LOG_PATH}${file}")
  done

  bin/docker-compose exec phpfpm tail -f "${logs_file_path[@]}"
fi

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions