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!

2

1 Answer 1

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.