Shell script get name of first file in folder fails because of double quotes?

Hi all,

I thought I had the following Shell Script working in KM, but turns out it's not. It's supposed to change directory to the export folder, and get the filename of the first file it finds. Definitely works in Terminal (with an absolute path, not a KM variable) but won't get the filename when run in KM.

cd $KMVAR_export_Folder files=(*) echo "$files" # since we are only concerned with the first element
I think it's failing because of the double quotes around $files. Any ideas how to get this to work?

Many thanks if you can help

The double quotes around $files are not the problem. The problem is most likely the lack of double quotes around $KMVAR_export_Folder. If there are any spaces in that path, the cd command will fail unless that variable is quoted.

There are other possibilities, mainly if $KMVAR_export_Folder is a relative path instead of an absolute path.

PS:
To make your scripts appear with line breaks, put lines of three backticks before and after the lines of code. It makes the code easier for others to read.

1 Like

Ugh, I knew I'd had it working before. Thanks for the tip-off. All back to normal now.