zoukankan      html  css  js  c++  java
  • [Bash] Add Executable Files to $PATH with Bash

    $PATH

    PATH is a global environment variable that represents a list of directories bash looks in for executable files. The executable files for bash commands like grep are all somewhere on your OS’s PATH. We can add our own folders to PATH to make our executables available as a command to bash. In this lesson we’ll learn how to add a new folder to our PATH in .bash_profile and how to symlink an executable file into /usr/local/bin, which is in PATH by default.

    Note that in zsh, when modifying your PATH you to provide an absolute path, ~ is not expanded.

    You can see the PATH:

    echo $PATH
    

    You can see one executable command where it located:

    which ng
    

    Add your executable command to the $PATH:

    export PATH="$PATH:~/my-scripts"
    

    Make the script:

    mkdir -p my-scripts
    echo 'echo hello' > my-scripts/hello
    chmod +x my-scripts/hello
    source .bash_profile
    

    Then run hello, you shoul see the output.

    Other way

    Another way to add an executable to $PATH is by symlinking an executable file into an existing folder that is always in $PATH.

    echo 'echo hello2' > my-scripts/hello2
    ln -s ~/hello2 /usr/local/bin
    
  • 相关阅读:
    labview 中的一些简写全称
    socket
    putty
    在波形图表中显示多条曲线
    简单的通电延时触发电路
    Linux sed 批量替换多个文件中的字符串
    PhpMyAdmin管理,登录多台远程MySQL服务器
    MySQL客户端工具推荐
    Redis的几个认识误区
    Redis 的 5 个常见使用场景
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14397768.html
Copyright © 2011-2022 走看看