环境变量和Bash内置命令

Command Line Editing

bash 复制代码
Ctrl+a#Move to the start of the line.(光标移到最前面)
Ctrl+e#Move to the end of the line.(光标移到最后面)
Ctrl+l#Clear the screen, reprinting the current line at the top.(不等同clear命令.会在顶部重新打印当前行,当前行还有内容时,还会显示)
#####demo
[root@kafka100 temp]# ls
heap.c
[root@kafka100 temp]# pwd
/root/workspace/cpp/temp
[root@kafka100 temp]# fdsfg
#####此时按下Ctrl+l,将变为下面,可以看到当前行的内容还在
[root@kafka100 temp]# fdsfg

环境变量

bash 复制代码
[root@kafka100 temp]# /root/workspace/cpp/temp/heap
Current heap end address: 0x15c8000
[root@kafka100 temp]# $(pwd)/heap
Current heap end address: 0x659000
[root@kafka100 temp]# ./heap
Current heap end address: 0x1960000
[root@kafka100 temp]# heap
bash: heap: command not found
# 原因:当前目录并不在PATH环境变量里
# 当可执行文件heap处于PATH环境变量的路径里时,执行的时候,就可以省去./了。
bash 复制代码
shell variable只有当前shell进程可以使用,当前shell的子进程访问不到

#使当前shell进程的子进程也可以使用
export TEST="test"
export [-fn] [-p] [name[=value]]
#使shell variable可以被当前shell的子进程使用
Mark each name to be passed to child processes in the environment.
If the -f option is supplied, the names refer to shell functions;otherwise the names refer to shell variables.
The -n option causes the export property to be removed from each name.
#让每个shell及其子进程,都能使用该环境变量,将export variable_name=value命令写到Bash的Startup files中

#If no options or arguments are supplied,set displays the names and values of all shell variables and functions.
set
#env和printenv的输出一样
printenv#列出所有的环境变量(If no VARIABLE is specified, prints the value of every environment variable.)
printenv JAVA_HOME KAFKA_HOME#Print the values of the specified environment VARIABLE(s).
env#Output the current environment.

Bash Variables

bash 复制代码
_:
At shell startup, set to the absolute pathname used to invoke the shell or shell script being executed as passed in the
environment or argument list.
Subsequently, expands to the last argument to the previous command, after expansion.
Also set to the full pathname used to invoke each command executed and placed in the environment exported to that command.
When checking mail, this parameter holds the name of the mail file currently being checked.

BASH_VERSION:Expands to a string describing the version of this instance of bash.
BASH_VERSINFO:A readonly array variable whose members hold version information for this instance of bash.
BASH_VERSINFO[0]#The major version number(the release).
BASH_VERSINFO[1]#The minor version number(the version).
BASH_VERSINFO[2]#The patch level.
BASH_VERSINFO[3]#The build version.
BASH_VERSINFO[4]#The release status(e.g., beta1).
BASH_VERSINFO[5]#The value of MACHTYPE.

HOSTNAME:the name of the current host.
HOSTTYPE:uniquely describes the type of machine on which bash is executing.
MACHTYPE:fully describes the system type on which bash is executing,in the standard GNU cpu-company-system format.

#每次打印提示符之前执行(bash5.1版本中可以是一个数组变量,此时每个元素包含的命令都会执行)
#Bash examines the value of the array variable PROMPT_COMMAND just before printing each primary prompt.
PROMPT_COMMAND:If set, the value is executed as a command prior to issuing each primary prompt.
#读取命令后,执行命令前(bash4.4版本才有的)
PS0:Expanded and displayed by interactive shells after reading a complete command but before executing it.
#提示符(就是每次输命令前面的[root@kafka100 cpp]#)
PS1:The primary prompt string.

BASHOPTS:A colon-separated list of enabled shell options.The options appearing in BASHOPTS are those reported as on by shopt.

Bash Builtin Commands

bash 复制代码
#Enable and disable builtin shell commands.
#Disabling a builtin allows a disk command which has the same name as a shell builtin to be executed without
#specifying a full pathname, even though the shell normally searches for builtins before disk commands.
#If -n is used, the names become disabled.Otherwise names are enabled.
#If the -p option is supplied, or no name arguments appear, a list of shell builtins is printed.
#The -a option means to list each builtin with an indication of whether or not it is enabled.
enable
enable -n test#禁用test内置命令(use the test binary found via $PATH instead of the shell builtin version)

#For each name, indicate how it would be interpreted if used as a command name.
#If the -t option is used, type prints a single word which is one of 'alias', 'function', 'builtin', 'file' or 'keyword',
#if name is an alias, shell function, shell builtin, disk file, or shell reserved word, respectively.
#If the -a option is used, type returns all of the places that contain an executable named file.
type [-afptP] [name ...]
type -t cat;type -t echo
type -a echo;type -a type;type -a ls;type -a for

whereis#locate the binary, source, and manual page files for a command
whereis echo#列出echo的二进制文件路径,源码文件路径,man手册文件路径

#Toggle the values of settings controlling optional shell behavior.
#With no options,or with the -p option,a list of all settable options is displayed,with an indication of whether
#or not each is set.
shopt

#Display current Readline key and function bindings, bind a key sequence to a Readline function or macro,
#or set a Readline variable.
bind -P >bind_output

https://wiki.calculate-linux.org/bash_shortcuts

https://www.gnu.org/software/bash/manual/bash.html

https://man7.org/linux/man-pages/man1/printenv.1.html

https://www.gnu.org/software/coreutils/manual/html_node/printenv-invocation.html

https://tiswww.case.edu/php/chet/bash/CHANGES

https://unix.stackexchange.com/questions/584003/what-does-the-export-command-do-to-a-variable

https://stackoverflow.com/questions/1158091/defining-a-variable-with-or-without-export

https://www.gnu.org/software/coreutils/manual/html_node/env-invocation.html#env-invocation

https://help.ubuntu.com/community/EnvironmentVariables

https://superuser.com/questions/881897/what-are-the-differences-between-sh-file-sh-and-source-file-sh

相关推荐
程序员敲代码吗15 小时前
如何通过命令行启动COMSOL的参数化、批处理和集群扫描
java·c#·bash
dingdingfish1 天前
Bash 学习 - 第1章:Introduction
bash·shell·programming·introduction
xuchaoxin13752 天前
bash中的字符串处理@输出和格式化打印@echo@printf
chrome·bash
xuchaoxin13752 天前
bash@特殊字符@环境变量符号@特殊参数@参数扩展和替换@字符串处理用法总结
开发语言·bash
dingdingfish2 天前
Bash 学习 - 第2章:Definitions
bash·definition
xuchaoxin13752 天前
bash@参数扩展@参数转换@参数扩展操作符
bash
提娜米苏3 天前
非Root环境下的数据挂载解决方案:SSHFS与Mount详解
bash·sshfs
这儿有一堆花3 天前
任何东西都可以转成 Base64!?
bash
wasp5203 天前
Banana Slides 深度解析:AI Core 架构设计与 Prompt 工程实践
人工智能·prompt·bash
市场部需要一个软件开发岗位3 天前
一个无人机平台+算法监督平台的离线部署指南
java·python·算法·bash·无人机·持续部署