Identify Shell Environment Types

Identify Shell Environment Types

Goal: Understand how to identify shell login and non-login environments

语法:echo $0
  输出 -bash 代表:shell登录环境
  输出 bash 代表:shell非登录环境
  注意:这个$0环境变量如果用在子shell中(shell脚本文件中)输出shell脚本本身的文件名 
 bash 命令 用于切换shell非登录环境

Introduction to switching shell environment commands

# 切换到指定用户,加载shell登录环境变量
	su 用户名 -l 或者 su 用户名 --login 
# 切换指定用户 加载shell非登录环境变量
  su 用户名

Shell String Variables: Format Introduction

目标:
	能够使用字符串的三种方式
  掌握3种方式的区别
  能够获取字符串长度

string writing

字符串的三种格式
    1.单引号方式
    2.双引号方式
    3.不用引号方式
    
字符串的3种格式的区别
    1.使用单引号的字符串 在拼接字符串中使用变量是无效的都会原样输出,不会识别变量
    2.使用双引号的字符串 那么该变量会解析出来值,而不是原样输出,字符串中还可以出现双引号的子字符串,但是需要转义 转义字符是\
    3.不被引号包围的字符串中出现变量也会解析,但是字符串中不能出现空格,否则空格后面的字符串会作为其他命令解析

获取字符串的长度
    语法:${
    
    #字符串变量名}

String concatenation

字符串拼接的三种方式
  1.无符号拼接
  2.双引号拼接
  3.混合拼接

insert image description here

String interception

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_44590469/article/details/122647822