bash 中 ${-#*i} 是什么意思?


author: hjjdebug

date: 2024年 12月 25日 星期三 17:43:45 CST

description: bash 中 ${-#*i} 是什么意思?


在centos 的 /etc/profile 中有这样的语句

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do

if [ -r "$i" ]; then

if [ "{-#\*i}" != "-" ]; then

. "$i" #是交互式shell, 直接source

else

. "$i" >/dev/null #非交互式shell, 将输出重定向到空

fi

fi

done

其中难理解的是:${-#*i}

${-#*i}, 是一个变量置换.

$-: 是一个内置变量,是外壳shell的标志集合,是一个字符串, 我的是himBHs

#是元字符,*也是元字符,i不是元字符,就是字符"i"

是从左侧开始查找并删除匹配的意思,最小匹配 ${parameter#[word]} :

是最大匹配 ${parameter##[word]} :

* 是匹配任何字符

i 是字面意义的i字符

if [ "{-#\*i}" != "-" ] 语句含义:

前部分是变量替换,最小匹配删除从开始到i字符为止得到新变量,与原变量相比

不等就是字符串带i, 等于就是字符串不带i

带i, 则说明shell 是interactive 的, 是交互式shell

相关推荐
归叶再无青12 小时前
web服务安装部署、性能升级等(Apache、Nginx)
运维·前端·nginx·云原生·apache·bash
归叶再无青13 小时前
企业级web服务(Tomcat开源web应用服务器)
运维·前端·开源·tomcat·bash
chao_7892 天前
构建start_app.sh,实现快速启动项目
python·bash·终端·前后端
笨笨D幸福2 天前
应用程序重定向技术(Shim)
bash·scoop·shim
xuchaoxin13753 天前
bash@bash帮助命令help@bash命令可用选项设置@bash -c@set命令@set --
bash
ol木子李lo3 天前
Linux 命令备忘录
linux·运维·服务器·windows·编辑器·ssh·bash
dingdingfish5 天前
Bash学习 - 第10章:Installing Bash
bash·make·shell·install·configure·5.3
dingdingfish5 天前
Bash学习 - 第8章:Command Line Editing,第3节:Readline Init File
bash·init·bind·readline
dingdingfish6 天前
Bash学习 - 第8章:Command Line Editing,第6-8节:Programmable Completion
bash·shell·completion·complete·compgen·compopt
dingdingfish6 天前
Bash学习 - 第8章:Command Line Editing,第4-5节:Bindable Readline Commands
bash·emacs·vi·bind·readline