I am trying to store a list of specific files into a variable in expect.
In my script, I am trying to compile files that have different file extensions, like .foo, .bar.
In this example, I have the following files:
To get just .foo files, I tried to run this:
set files "[exec ls -h | grep -E '\.foo' | rev | cut -c5- | rev]" send_user "$files\n"
I was expecting to see:
However, I ended up getting this error message:
child process exited abnormally while executing "exec ls -h | grep -E '\.foo' | rev | cut -c5- | rev" invoked from within "set files "[exec ls -h | grep -E '\.foo' | rev | cut -c5- | rev]"" (file "./runthis.sh" line 2)
I know I could use
ls -h *.foo,
awk, etc. I noticed the pattern... with
find, expect wigs out if I use the
' (single quote), so that pretty much eliminates the idea of using
grep. If I use
ls -h *.foo and the files don't exist, the script will stop. It is supposed to continue checking and listing other files.
If it finds the files, it will eventually be split into an array using this command:
set split_files "[split $files \n]"