1

I have aliased a long path in .bashrc file as

alias py="cd ~/Myprograms/Langs/workout/PythonScripts"

Now assume there is an another directory in PythonScripts say "basics"

How do I use the above alias without changing it, i.e, something like py/basics.

I tried this and it results in error

bash: py/basics: no such file or directory

How do I do this ?

1 Answer 1

4

This can't be done with bash aliases, but you can use functions:

py () {
  cd ~/Myprograms/Langs/workout/PythonScripts/"$1"
}

$1 is the first argument to the function. You can call it this:

py basics

Without any arguments, it would just cd to ~/Myprograms/Langs/workout/PythonScripts/.

5
  • Come on muru, i need some spare points ;)
    – heemayl
    Dec 20, 2015 at 9:37
  • @heemayl bounties to be granted? I can help.
    – muru
    Dec 20, 2015 at 9:39
  • @heemayl That's a bit beyond what Stack Exchange will let me grant. :P
    – muru
    Dec 20, 2015 at 9:42
  • well then ....good for you ;)
    – heemayl
    Dec 20, 2015 at 9:43
  • Now if only this worked with bash-completion Feb 21, 2016 at 22:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .