环境变量和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

相关推荐

  1. 环境变量Bash命令

    2024-03-18 08:56:02       17 阅读
  2. Linux yum/环境变量/服务/进程/hash/bash/防火墙命令

    2024-03-18 08:56:02       17 阅读
  3. Jenkins 变量 变量作用域

    2024-03-18 08:56:02       11 阅读
  4. 【UnityShader预备知识】变量函数

    2024-03-18 08:56:02       15 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-18 08:56:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-18 08:56:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-18 08:56:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-18 08:56:02       20 阅读

热门阅读

  1. 华为云APIG跨域资源共享方案

    2024-03-18 08:56:02       14 阅读
  2. 【数据库】MySQL数据库基础

    2024-03-18 08:56:02       18 阅读
  3. 如何在MATLAB中进行循环和条件语句?

    2024-03-18 08:56:02       21 阅读
  4. Vue-- 实现简单版 vue-router

    2024-03-18 08:56:02       18 阅读
  5. C语言中大小写字母是如何转化的?

    2024-03-18 08:56:02       23 阅读
  6. Euler angles and Quaterean

    2024-03-18 08:56:02       21 阅读
  7. Leetcode 第388场周赛 问题和解法

    2024-03-18 08:56:02       22 阅读