Linux命令——source
前言
当我们修改了/etc/profile文件,并想让它立刻生效,而不用重新登录,就可以使用source命令,如source /etc/profile。
source命令
source是一个内建命令。下面命令执行环境是Ubuntu 16.04.3 LTS下的bash。事实上source命令并不是bash(Bourne shell)内置的,他是GNU项目后来扩展引入的。其他shell不确定是否有source命令。
Linux命令——type、which、whatis、apropos、whereis、find

root@ubuntu:~# type source
source is a shell builtin
除了type可以查看source,help命令也可以

root@ubuntu:~# help source source: source filename [arguments] Execute commands from a file in the current shell. Read and execute commands from FILENAME in the current shell. The entries in $PATH are used to find the directory containing FILENAME. If any ARGUMENTS are supplied, they become the positional parameters when FILENAME is executed. Exit Status: Returns the status of the last command executed in FILENAME; fails if FILENAME cannot be read.
但是man,whatis命令就不可以查看source命令了

root@ubuntu:~# man source No manual entry for source root@ubuntu:~# whatis source source: nothing appropriate.
考虑到和其他shell的兼容性,最好使用点号 . 。点号.是source的同义词,为啥使用source而不是.,可能的原因是:写.有时候看起来像是写错了的命令,用source更直观。
但是从简洁的角度看,实在没必要打那么多字来实现一个和.一样的功能
./ 和 source 不完全一样
./script
runs the script as an executable file, launching a new shell to run itsource script
reads and executes commands from filename in the current shell environment
Note: ./script
is not . script,
but . script
== source script
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决