• 0 Posts
  • 20 Comments
Joined 1 year ago
cake
Cake day: June 7th, 2025

help-circle
  • By default bash will only expand an alias if it’s the first argument of the command (that is, the command itself).

    It’s probably not intended to use aliases this way, and there are probably better options for you.

    However, there is a little trick you can do. If the alias command ends in a space, then bash will also check the next argument:

    alias cd='cd '

    Notice the trailing space after ‘cd’ in the alias definition.

    alias docs='/media/docs'

    then, cd docs should work the way you expect.

    Another method would be to:

    alias docs='echo /media/docs'

    Then you can do

    cd `docs`  
    

    The backticks will cause the shell to replace that portion with the output of the docs shell command, which will be expanded via the alias.

    All that said, it’s probably easiest just to use a link, like another commenter suggested.