1

I have a file called ~/.gotorc and in it I have

alias goto_usr="cd /usr"
alias goto_bin="cd /user/local/bin"

Then in my .zshrc I have

source ~/.gotorc
goto() {
    `goto_$1`
}

But when I run goto bin, it says goto:bin: command not found: goto_bin. But if I run goto_bin then it works and I go to the expected folder.

How come?

1
  • 1
    .zshrc is used with zsh, not bash. You want to use .bashrc instead. Commented Oct 14, 2016 at 20:08

1 Answer 1

2

Instead of aliases you can define a single function goto like this:

goto() {
    case "$1" in
       usr)
       cd /usr;;
       bin)
       cd /usr/local/bin;;
    esac
}

Then use it as:

goto usr
goto bin
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.