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:
- something.foo
- something_new.foo
- something_different.bar
- this_is_the_wrong_one.sh
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:
- something
- something_new
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 find '*.foo', 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 find, awk, and 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:
Update 1:
set split_files "[split $files \n]"