I rarely use tcsh
, but you should be able to achieve what you want using the globdot
option1:
globdot (+)
If set, wild-card glob patterns will match files and directo‐
ries beginning with `.' except for `.' and `..'
So
#!/bin/tcsh
set globdot
foreach current ($1:q/$run_folder:q/*)
printf '%s\n' $current:q
end
Beware it errors out with a No match error if there's no non-hidden file in the directory.
That can be worked around by including a wildcard known to match along with *
:
#!/bin/tcsh
set globdot
set files = (/de[v] $1:q/$run_folder:q/*)
shift files
foreach current ($files:q)
printf '%s\n' $current:q
end
BTW, the correct syntax for bash
would be:
#! /bin/bash -
shopt -s nullglob dotglob
for current in "$1/$run_folder"/*; do
printf '%s\n' "$current"
done
You had forgotten the quotes around your expansions, that echo
can't be used for arbitrary data, and that by default non-matching globs are left unintended. The dotglob
option (equivalent of csh/tcsh/zsh's globdot
option) avoids the need for those 3 different globs.
Notes:
- The
(+)
indicates that the feature is "not found in most csh(1) implementations (specifically, the 4.4BSD csh)"
-exec
fromfind
... Do you have a reason to avoidfind
? – Kusalananda Jun 14 '20 at 10:20tcsh
script with logic in thefor
loop (not just printing thecurrent
). so it will be long for-exec
– vesii Jun 14 '20 at 10:23-exec
can execute arbitrary commands, that does not sound like restriction. As soon as you have a script that takes pathnames as command line arguments, you could execute it withfind "$1/$run_folder" -exec scriptname '{}' +
– Kusalananda Jun 14 '20 at 10:37for
loop to be part of that script. In a shell script - iterate over the files/dirs in given path and do logic (like moving, removing and editing stuff). I don't want to have another script that does the logic. – vesii Jun 14 '20 at 10:40