【shell】What does “${-#*i}” != “$-” mean?

# cat  /etc/profile


【shell】What does “${-#*i}” != “$-” mean?_第1张图片


这段代码的意思是:

对于/etc/profile.d/目录下以.sh结尾的文件

如果现在执行的命令(或脚本)是交互式(interactively),那么加载之

如果执行的命令(或脚本)是非交互式(non-interactively),那么加载之,并且将输出重定向到 /dev/null ,目的是防止有些执行某些程序(如scp),需要登录到远端机器,读取远端机器的环境变量有输出,导致程序中断!

如果使用scp或sftp等程序传输文件,则将任何文本打印到标准输出都是有害的,验证当前shell是非交互式后退出是.bashrc最安全的行为。

【shell】What does “${-#*i}” != “$-” mean?_第2张图片


【shell】What does “${-#*i}” != “$-” mean?_第3张图片


What does “${-#*i}” != “$-” mean?

https://unix.stackexchange.com/questions/129231/what-does-i-mean


What does “[[ $- != *i* ]] && return” mean?

https://askubuntu.com/questions/829069/what-does-i-return-mean


Why does bashrc check whether the current shell is interactive?

https://unix.stackexchange.com/questions/257571/why-does-bashrc-check-whether-the-current-shell-is-interactive


SCP fails without error

https://unix.stackexchange.com/questions/18231/scp-fails-without-error/18647#18647


scp breaks when there's an echo command in /etc/bashrc

https://bugzilla.redhat.com/show_bug.cgi?id=20527


Bash Startup Files

https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html


Linux set命令

http://www.runoob.com/linux/linux-comm-set.html


Linux unset命令

http://www.runoob.com/linux/linux-comm-unset.html

你可能感兴趣的:(【shell】What does “${-#*i}” != “$-” mean?)