1

In bash shell, what is the command to go to a special directory based on two input arguments?

The command I want to get executed is this:

cd /home/btfoouser/mia_YOCTO/build_4/build/tmp-eglibc/deploy/images/p99/

I want to pass build4 and p99 as my input arguments to the cd command from the command line.

For example, the command will be my_cd build_4 p99, which should get translated to

cd /home/btfoouser/mia_YOCTO/build_4/build/tmp-eglibc/deploy/images/p99/

I tried:

alias my_cd ='cd /home/btfoouser/mia_YOCTO/$1/build/tmp-eglibc/deploy/images/$2'
1
  • Please follow this URL it will be useful to help you to lift your content quality up Commented Jun 17, 2016 at 2:24

1 Answer 1

3

Aliases don't parse arguments. Use a function:

my_cd() { cd "/home/btfoouser/mia_YOCTO/$1/build/tmp-eglibc/deploy/images/$2"; }

To make the function permanent, put it in your ~/.bashrc file.

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

2 Comments

There is a dirty hack for making aliases take arguments : alias my_cd='{ read x y; cd "/home/btfoouser/mia_YOCTO/$x/build/tmp-eglibc/deploy/images/$y"; } <<<' & then my_cd "dir1 dir2" This is of course, not a recommendation, but just for information...
@anishsane Nice evil hack!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.