-1

No idea what's happening here. I am on Bash 3.2 on a Mac. I have:

ores_resource(){
  for f in "$(cd "$HOME/.oresoftware/bash" && find . -type f)"; do
       f="${f:2}"
       echo "my file $f"
  done;
}

I get this echoed out:

my file r2g.sh
./fame.completion.sh
./read_json.sh
./nlu.sh
./lmx.sh
./public-bash-utils.sh
./run-tsc-if.sh
./r2g.completion.sh
./fame.sh
./waldo.sh
./nlu.completion.sh

so what the heck is going on here - I thought it would log out "my file" in front of each of the lines?

1 Answers1

2

Here is a solution using find with the -exec option:

ores_resource() {
  cd $HOME/.oresoftware/bash
  find . -type f -exec bash -c 'echo "my file ${1:2}"' bash {} \;
}

For each filename found by find a new bash process is started with the command string following -c. Each filename {} is passed as argument $1 to the bash process (like your variable $f).

Freddy
  • 25,565