11

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
roninkelt
  • 111
  • 1
  • 3

2 Answers2

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
-3

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.

41754
  • 85
  • 1
  • 7
  • 19