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'
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Benny John
  • 19
  • 2
  • Please follow this [URL](http://stackoverflow.com/help) it will be useful to help you to lift your content quality up – Willie Cheng Jun 17 '16 at 02:24

1 Answers1

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.

John1024
  • 109,961
  • 14
  • 137
  • 171
  • 3
    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 Jun 17 '16 at 04:14
  • @anishsane Nice evil hack! – John1024 Jun 17 '16 at 04:32