0

I am trying to find the file names in a path. Using following script, but getting issue when tries to put that name in a variable:

for file in "${PROJECT_DIR}/temp_namespaces"/*
do
    echo "${file##*/}"
    namespaces= "${file##*/}"
    echo "namespace = " > "${namespaces}"
done

it prints the file name from first echo, but after that both lines gives error:

namespaces= "${file##*/}"                ----   command not found
echo "namespace = " > "${namespaces}"    ----  No such file or directory

I am using linux available on amazon/aws-cli base image to run the above script.

I need to get the file names from a path and store them in a variable that will be used later in script to run few more commands.

Any pointers are appreciated.

Thanks

1 Answers1

0

Strangely I found that script got fixed when removed space and quotes from following line:

namespaces= "${file##*/}"

and changed it as:

namespaces=${file##*/}

removing one space and quotes, that's all.

  • Nothing strange. Spaces around `=` [do matter](https://superuser.com/a/1669093/432690); and it's [one of few cases where double-quotes don't matter](https://unix.stackexchange.com/q/68694/108618). The space was the culprit, the quotes could stay. – Kamil Maciorowski Jul 20 '23 at 12:33