当前位置: 首页 > article >正文

环境变量和Bash内置命令

Command Line Editing

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

环境变量

[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环境变量的路径里时,执行的时候,就可以省去./了。
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

_:
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

#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


http://www.kler.cn/a/273417.html

相关文章:

  • 华为od技术一面
  • Axure大屏可视化模板:赋能各行各业的数据展示与管理
  • 防重方案-订单防重方案笔记
  • UFO:Windows操作系统的具象智能代理
  • 1.探索WebSocket:实时网络的心跳!
  • 【LQB15_模拟】C风险对冲
  • android 顺滑滑动嵌套布局
  • Mac玩《幻兽帕鲁》为什么打不开D3DMetal?d3d错误怎么办 d3dxl error
  • 基于YOLOv8深度学习的橙子病害智能诊断与防治系统【python源码+Pyqt5界面+数据集+训练代码】深度学习实战、目标分类
  • mac清除dns缓存指令 mac清除缓存怎么清理
  • 复制word文档,合并word文档
  • 【vscode】vscode重命名变量后多了很多空白行
  • 计算地球圆盘负荷产生的位移
  • Ubuntu 搭建gitlab服务器,及使用repo管理
  • 利用textarea和white-space实现最简单的文章编辑器 支持缩进和换行
  • vue使用element-ui 实现自定义分页
  • TT-100K数据集,YOLO格式
  • MR混合现实情景实训教学系统在汽车检修课堂中的应用
  • 汽车电子零部件(8):T_Box
  • vsto excel 插件注册表属性值含义
  • linux学习之Socket
  • 多ip多进程代理的实现方法
  • Github 2024-03-18开源项目日报Top10
  • 动态规划(蓝桥杯 C++ 题目 代码 注解)
  • [TJOI2010] 阅读理解 **STL**Tire树**
  • 003——移植鸿蒙