Rollie
Rollie

Reputation: 4750

How to run a python script in bash, and use the output for cd?

I want to do:

alias go=cd $(go.py $1)

then run

?> go home

go.py prints some directory (/my/special/home), which is used by cd to go to that location. But, it doesn't work. If I change the alias to:

alias go=cd $(go.py home)

it works fine, but I want it to be a bit more configurable. Something with the syntax I don't understand I assume.

Upvotes: 1

Views: 57

Answers (1)

hek2mgl
hek2mgl

Reputation: 158130

Use a function instead of an alias:

function go() {
    cd "$(go.py "${1}")"
}

Upvotes: 3

Related Questions