9

I'm constrained to doing this in tcsh on CentOS due to the environment at work. When executing find . -type f -executable -exec source '{}' \; the only result is find: 'source': No such file or directory for each appropriate file. Not sure why this isn't working in tcsh as it's pretty straightforward. What am I doing wrong? Any help greatly appreciated.

2 Answers 2

7

source is a shell builtin. find executes commands. It cannot execute a shell builtin.

If you want to execute external programs, just specify the program name:

find . -type f -executable -exec '{}' \;

If these are all csh scripts lacking a shebang like (#!/bin/env csh as the first line), add a shebang line. If you really can't add a shebang line, call csh explicitly:

find . -type f -executable -exec tcsh '{}' \;

If these are all csh script fragments that you want to execute inside the current shell, you can't do it this way. You'll need to collect the names with find and then source them.

foreach fragment ("`find . -type f -executable -print`")
  source "$fragment"
end

There's something fishy about this requirement in the first place. Shell fragments meant to be sourced should not be executable.

1
  • didn't realize that about find -exec and shell builtins. Thanks for the insight.
    – roninkelt
    Jan 15, 2014 at 15:00
-2

See this:

127:2:1389633116:user@host:~$ tcsh source foo
source: No such file or directory.
1:3:1389633119:user@host:~$ tcsh
host:~> source foo
foo: No such file or directory.
host:~> exit
0:4:1389633582:user@host:~$ tcsh -c 'source foo'
foo: No such file or directory.

Try those yourself, and others. Maybe inspecting strace traces. Finally try to take advantage and build a workaround.

4
  • I have no idea where you're getting at with this answer. Jan 13, 2014 at 23:12
  • I'm telling the questioner to do $ find . -type f -executable -exec tcsh -c 'source {}' \;
    – 41754
    Jan 14, 2014 at 8:02
  • The comment answer above is exactly what I was after, combined with the insight about shell builtins and exec from the first answer completely answers my question. Thanks so much.
    – roninkelt
    Jan 15, 2014 at 14:59
  • You are welcome, wherever you are!
    – 41754
    Oct 9, 2019 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.