Home>

Because it's cumbersome to run a tool written in a shell script by specifying the path one by one, I want to be able to execute it only with the file name (ie I want to pass the path)

For example, if you develop with golang,go getorgo installwill install it in the specified location ($GOPATH). There is no such mechanism.

There are various realization methods, but I asked which method I thought was better. Thank you

How you thought
  • Pass a new path to the directory used for tool development (this is unlikely)
  • Place the script file directly in the pathed directory (for example,/usr/local/bin/)
  • Create a symbolic link from the directory used for tool development to the directory where the path has passed
  • Create a directory for the shell script and pass the new path
  • Create a directory in which to place the shell script, and create a symbolic link from there to the directory that passed the path
  • Answer # 1

    There is no "best" of this kind.

    If it is general-purpose that is not project-specific, it is usually placed in~/bin/.
    At least for CentOS, set the default~/.bash_profileto

    PATH = $PATH: $HOME/bin


    There is.

  • Answer # 2

    I think it depends on how the tool is used, but if you only use it (such as a laptop) or if you use it on some server,/usr/I think I should put it in local/bin. Most OS should be through the path.

    If you don't want anything on the server, you can get it directly from Git with Curl and pipe it, but this is not always the script on the server (if you have a lot of servers) It is effective sometimes, but otherwise it is subtle.