source

Linux source命令:

通常用法:source filepath 或 . filepath

功能:使当前shell读入路径为filepath的shell文件并依次执行文件中的所有语句,通常用于重新执行刚修改的初始化文件,使之立即生效,而不必注销并重新登录。例如,当我们修改了/etc/profile文件,并想让它立刻生效,而不用重新登录,就可以使用source命令,如source /etc/profile。

source命令(从 C Shell 而来)是bash shell的内置命令;点命令(.),就是个点符号(从Bourne Shell而来)是source的另一名称。这从用法中也能看出来。

 

source filepath 与 sh filepath 、./filepath的区别

  1. 当shell脚本具有可执行权限时,用sh filepath与./filepath是没有区别的。./filepath是因为当前目录没有在PATH中,所有"."是用来表示当前目录的。

  2. sh filepath 会重新建立一个子shell,在子shell中执行脚本里面的语句,该子shell继承父shell的环境变量,但子shell是新建的,其改变的变量不会被带回父shell,除非使用export。

  3. source filename其实只是简单地读取脚本里面的语句依次在当前shell里面执行,没有建立新的子shell。那么脚本里面所有新建、改变变量的语句都会保存在当前shell里面。

 

举例说明:

  1. 新建一个test.sh脚本,内容为:A=1;

  2. 修改其可执行权限:chmod +x test.sh;

  3. 运行sh test.sh后,echo $A,显示为空,因为A=1并未传回给当前shell;

  4. 运行./test.sh后,也是一样的效果;

  5. 运行source test.sh 或者 . test.sh,然后echo $A,则会显示1,说明A=1的变量在当前shell中;

转载于:https://www.cnblogs.com/Cohen/p/9022779.html

06-07
### SOURCE in Programming or Data Context In the context of programming and data, the term **SOURCE** can refer to multiple concepts depending on the specific domain being discussed. Below is a detailed explanation of what **SOURCE** might represent in various technical contexts: #### 1. Source Code The most common usage of the term **SOURCE** in programming refers to **source code**, which is the human-readable version of a program written in a programming language such as Ruby[^3]. This source code is later compiled or interpreted into machine-executable code. #### 2. Data Source In the context of data, **SOURCE** often refers to the origin or provider of data. For example: - In file I/O operations, the source could be a file from which data is read[^2]. - In database systems, the source might refer to tables, views, or external APIs that supply data. - In web development, the source could be an API endpoint or a database query result. #### 3. Input Source When discussing input/output (I/O) operations, the term **SOURCE** may describe where the input originates. For instance, in serial I/O, the source of data might be a device connected via a serial port, which typically involves slower transmission speeds compared to file I/O[^2]. #### 4. Context Programming In certain paradigms like **controller and context programming**, the concept of **SOURCE** might relate to the selection of elements within a user interface. For example, when choosing a context element in a table line, the source could be the marked line itself, even though related elements are not automatically selected[^4]. #### 5. Object-Oriented Perspective From an object-oriented standpoint, particularly in languages like Ruby[^3], **SOURCE** could also imply the origin of method calls or data flow between objects. For instance, if one object invokes a method on another, the invoking object acts as the source of the interaction. ```python # Example demonstrating source in object-oriented programming class DataSource: def __init__(self, data): self.data = data def get_data(self): return self.data # The source of this data is the 'data' attribute source = DataSource("Sample Data") print(source.get_data()) # Output: Sample Data ``` ### Summary The term **SOURCE** in programming or data contexts can denote several entities, including source code, data origins, input devices, or even interactions in object-oriented systems. Its precise meaning depends heavily on the specific scenario being addressed.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值