0

I'm trying to do something similar to this post : Execute command on all files in a directory

I have a bunch of test files in a directory, and I need to run each test using a specific run command with multiple options.

  1. I tried using a for loop from a shell script, but I get the following errors :

for: Command not found. do: Command not found. f: Undefined variable.

Script :

#!/bin/csh
set FILES = ../../test_files/*.out
for f in $FILES; do
runcmd -option1 -option2 -option3 -option4 "$f" >> results.log
done
  1. I also tried using the find -exec commands, but I get the following error with this :

find: missing argument to `-exec'

I'm under the impression that I'm getting this error since I have multiple options in the command I'm trying to run.

Script :

#!/bin/csh
find ../../test_files -name "*.out" -exec run_cmd -option1 -option2 -option3 -option4 -- echo {} \ > results.log

I did chmod 777 on my script before trying to run it. And I also tried using running this same script in bash (by using #!/bin/bash in my .sh script and entering bash in the terminal), but I get the same error when I use find -exec, and the script doesn't do anything when I use the for loop.

Could someone please help me figure out why my scripts aren't working? or show me another way to execute the run command on all the test files in a directory?

Aurora.mn
  • 13
  • 3
  • 1
    Your `for` loop is using bash (/ksh/zsh/dash/just plain sh) syntax, which won't work in csh (/tcsh). In csh, you'd use `foreach` instead. As for `find -exec`, you need an escaped or quoted `;` to end the `-exec` section (it looks like you have an escaped space there instead, did a semicolon go missing?). – Gordon Davisson Jan 21 '22 at 02:53

1 Answers1

0

Thanks a lot @Gordon Davisson, I was able to fix my find command, and the script works now.

#!/bin/csh
find ../../test_files -name "*.out" -exec run_cmd -option1 -option2 -option3 -option4 -- echo {} \; > results.log
Aurora.mn
  • 13
  • 3