source

source 属于shell命令
shell 命令是操作kernel的。比如我们使用ifconfig。那么它就是去读取内核里面的net的ip然后按照格式打印出来。
Linux常用的shell版本是bash
执行文件有三中方式。
路径(./当前路径 绝对路径):需要执行权限的可执行文件
sh bash :使用bash执行可以不需要x
source:从当前内置shell会话中打开或执行一个文件。

使用路径和sh命令其实对于执行过程来讲是一样的。
我们打开一个terminal的时候
在这里插入图片描述
他也是一个process在这里他的pid是2970。
那我们在这个终端上的一些变量就是有作用域的。只能是在同一个进程中使用。就是2970的进程。
eg:
在这里插入图片描述
那么如果我在这个terminal执行一个程序,并且使用的在bash中定义的一个变量。这样可以吗?

#!/bin/bash
echo $name

分别使用./ bash sorce 去执行这个脚本
结果是:
./1.sh 没有执行权限
bash 打出来的是空格
souce :wzf.
在这里插入图片描述
这就是source.和其它两种执行方式的区别。
这是由于我们在终端一个命令的时候相当于
eg ping www.baidu.com
在这里插入图片描述
可以看到ping www.baidu.com的pid为5234 ppid为2970.
而pid为2970的进程是bash。这就是我在中端上打开一个进程其实就是bash创建了一个子进程。
还可以看到pid为5145的也是一个bash,那是因为我开了俩个中端。
回归正题。
为什么souce 可以打印出$name而其它俩种方式不可以呢。
./和bash是bash重新打开一个进程去执行脚本文件。。
而source是bash直接执行脚本文件。这样就用跨进程。
所以变量可以直接使用。
但是我们使用了export 这个关键字那么都可以使用,因为都是bash创建出来的子进程。

在这里插入图片描述
所以我们在编译android 之前使用souorce build/envtset.sh
这样在bash中使用.sh中定义的变量和函数比如lunch mmm
讲的很好

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、付费专栏及课程。

余额充值