Shell常识

本文介绍了Bash中的几个关键概念,包括使用.(dot)命令在当前环境中运行脚本、子shell的特点、fork系统调用创建进程的过程、&操作符用于后台运行进程的方法,以及一些实用的Bash快捷键。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

. DOT and Subshell

. (dot) runs a shell script in the current environment and then returns. Normally, the shell runs a command file in a subshell so that changes to the environment by such commands as cd, set, and trap are local to the command file. The . (dot) command circumvents this feature. 

A subshell does not inherit the environment variables from parent process.


Fork - system call
fork() creates a new process by duplicating the calling process. The new process, referred to as the child, is an exact duplicate of the calling process. However, child process has its own process id.

&

The Bash & (ampersand) is a builtin control operator used to fork processes. From the Bash man page, "If a command is terminated by the control operator &, the shell executes the command in the background in a subshell".


$BASHPID

Process ID of the current instance of Bash. This is not the same as the $$ variable, but it often gives the same result.

[oracle@odilab ~]$ echo $BASHPID
2540

$BASH_VERSION

The version of Bash installed on the system

[oracle@odilab ~]$ echo $BASH_VERSION
4.1.2(1)-release

Bash快捷键:

CTRL + R

查找历史命令。输入要查找的命令,ctrl + r 返回最近一个命令。再按ctrl + r 查看其他的。

CTRL + W

输入命令时,删除一个单词

CTRL + U

输入命令时,删除当前整条命令

CTRL + A

光标跑到行首。相当于"Home"键。

cd -

进入上一次的工作目录






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值