Q:

Bash: ${$(mycommand)%suffix} doesn't work to trim suffix from mycommand output

I am trying to change the directory to the remote location of my git repository. I am using the command:
cd ${$(git remote get-url origin)%.git}

The command doesn't work:
bash: ${$(git remote get-url origin)%.git}: bad substitution

I don't understand why this isn't correct. Is it because of the $() instead of using a variables name? If yes why? How can I do this correctly?

A:

You cannot use nested string substitution in bash.
Instead, you can use this one-liner:
cd $(git remote get-url origin | sed 's/\.git$//')

