From 8ae9a0fea57bd0e86a0cf5f4d849741f7fa2e5b9 Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Tue, 9 Jan 2024 14:55:54 -0300 Subject: [PATCH] fix correct script :facepalm: --- .github/scripts/copy_toml.sh | 56 +++++++++++++++++------------------- copy_toml.sh | 37 ------------------------ 2 files changed, 27 insertions(+), 66 deletions(-) delete mode 100755 copy_toml.sh diff --git a/.github/scripts/copy_toml.sh b/.github/scripts/copy_toml.sh index b5d6f31108d..3958cb79756 100755 --- a/.github/scripts/copy_toml.sh +++ b/.github/scripts/copy_toml.sh @@ -1,37 +1,35 @@ #!/bin/bash - # This script searches for TOML files matching given regex patterns and copies them to a target directory. +# This script searches for TOML files matching given regex patterns and copies them to a target directory. - echo "patterns: $1" - echo "search_folder: $2" - echo "target_folder: $3" +if [ "$#" -ne 3 ]; then + echo "Usage: $0 " + exit 1 +fi - if [ "$#" -ne 3 ]; then - echo "Usage: $0 " - exit 1 - fi +declare -a patterns=($1) # Array of regex filename patterns +search_folder=$2 # Folder to search in +target_folder=$3 # Target folder for copying files - declare -a patterns=($1) # Array of regex filename patterns - search_folder=$2 # Folder to search in - target_folder=$3 # Target folder for copying files +if [ ! -d "$search_folder" ]; then + echo "Search folder does not exist: $search_folder" + exit 1 +fi - if [ ! -d "$search_folder" ]; then - echo "Search folder does not exist: $search_folder" - exit 1 - fiwhy +mkdir -p "$target_folder" - mkdir -p "$target_folder" +copy_files() { + local pattern=$1 + # Find .toml files, extract filenames, and match pattern + find "$search_folder" -type f -name "*.toml" | while read -r file; do + filename=$(basename "$file") + if [[ $filename =~ $pattern ]]; then + cp "$file" "$target_folder" + fi + done +} - copy_files() { - local pattern=$1 - # Find .toml files, extract filenames, and match pattern - find "$search_folder" -type f -name "*.toml" | while read -r file; do - filename=$(basename "$file") - if [[ $filename =~ $pattern ]]; then - cp "$file" "$target_folder" - fi - done - } +for pattern in "${patterns[@]}"; do + copy_files "$pattern" +done - for pattern in "${patterns[@]}"; do - copy_files "$pattern" - done +echo "Copy operation completed." \ No newline at end of file diff --git a/copy_toml.sh b/copy_toml.sh deleted file mode 100755 index 544407aff1b..00000000000 --- a/copy_toml.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -# This script searches for TOML files matching given regex patterns and copies them to a target directory. - -echo "patterns: $1" -echo "search_folder: $2" -echo "target_folder: $3" - -if [ "$#" -ne 3 ]; then - echo "Usage: $0 " - exit 1 -fi - -declare -a patterns=($1) # Array of regex filename patterns -search_folder=$2 # Folder to search in -target_folder=$3 # Target folder for copying files - -if [ ! -d "$search_folder" ]; then - echo "Search folder does not exist: $search_folder" - exit 1 -fiwhy - -mkdir -p "$target_folder" - -copy_files() { - local pattern=$1 - # Find .toml files, extract filenames, and match pattern - find "$search_folder" -type f -name "*.toml" | while read -r file; do - filename=$(basename "$file") - if [[ $filename =~ $pattern ]]; then - cp "$file" "$target_folder" - fi - done -} - -for pattern in "${patterns[@]}"; do - copy_files "$pattern" -done