0

I'm trying to write a find and cd function like so:

findcd () {
        cd "$(dirname "$(find '$1' -type '$2' -name '$3')")"
}

to be called like so:

find . f [FILE_NAME]

But it's seeing the dollar sign and expecting more arguments as oppose to executing what's inside. I'm just starting with writing aliases and functions, so any advice would be super helpful!

Kusalananda
  • 333,661
Mathew
  • 235

1 Answers1

1

Try this:

findcd () {
        cd "$(dirname "$(find "$1" -type "$2" -name "$3")")"
}

The problem with your original attempt is that you had the variables single quoted so they were not being expanded. Also note that this will not work if you have more than one find result.

terdon
  • 242,166