This is probably a very simple thing but I can’t find an answer, possibly because I don’t know what terms to use in search.

How do I use an alias of a path with mv or cp? Or even cd?

In /etc/bash.bashrc I have: alias docs=‘/media/docs

cd docs Gives “No such file or directory”

Yet: docs Gives “Is directory”

With alias docs=‘cd /media/docs’ and by typing docs I get into the directory. Obviously I can’t use that alias with mv or cp though.

Maybe this isn’t even an intended use of alias but still. Why doesn’t it work?

  • davel@lemmy.ml
    link
    fedilink
    English
    arrow-up
    32
    ·
    2 days ago

    alias is for aliasing commands. If you want to “alias“ arguments, use shell/environment variables.

    $ docs=/media/docs
    $ cd $docs
    
    • teawrecks@sopuli.xyz
      link
      fedilink
      arrow-up
      8
      ·
      2 days ago

      It is worth acknowledging that this probably seems unintuitive to a new user. Makes it look like the shell has two different aliasing systems.

      It makes sense the more familiar you are with bash, though. If you ever tried to cd /some/other/path-with-docs/in/the/string you’d end up accidentally running cd /some/other/path-with-/media/docs/in/the/string.

      Which would be confusing at best, or a security issue at worst. Better to see that $ in the cmd and know you’re injecting a var’s value.

        • teawrecks@sopuli.xyz
          link
          fedilink
          arrow-up
          2
          ·
          12 hours ago

          This was an unknown unknown for OP. Again, it’s completely fair for a new user to see the alias feature, think “ah, that’s built for aliasing one thing to another, let me try it for this directory name”, and be confused when it doesn’t work. OP can’t know what they don’t know.

          And the open source community is just that, a community. Asking questions in forums is the accepted practice. And “basic” is hard to define. What is basic for you isn’t basic for someone else, in the same way that what is basic for someone else isn’t basic to you.

        • Black616Angel@discuss.tchncs.de
          link
          fedilink
          arrow-up
          3
          arrow-down
          1
          ·
          1 day ago

          Wow, you are unable to even read the post you reply under.
          They said that they don’t know, what terms to use for their search.