[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
posted @   Zhentiw  阅读(98)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2019-02-11 [HTML5] Add an SVG Image to a Webpage and Get a Reference to the Internal Elements in JavaScript
2019-02-11 [Angular] Angular i18n Alternative Expressions Support (select)
2019-02-11 [React + Functional Programming ADT] Create Redux Middleware to Dispatch Multiple Actions
2019-02-11 [React + Functional Programming ADT] Connect State ADT Based Redux Actions to a React Application
2019-02-11 [Functional Programming ADT] Create a Redux Store for Use with a State ADT Based Reducer
2019-02-11 [CSS3] Make a One-time CSS Animation that Does Not Revert to its Original Style
2017-02-11 [Ramda] Eliminate Function Arguments (Point-Free Style) with Ramda's Converge
点击右上角即可分享
微信分享提示