Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is being done here [ "${-#*i}" != "$-" ]

Tags:

bash

In RHEL6 /etc/profile near the end there's an if statement:

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

The != I'm guessing is the "not equal" for strings comparison operator. The left side I'm guessing is the string within the variable -@*i and the right side is the string within $- (which I think are the flags passed to the script). This is in the middle of a for loop and $i should exist however I don't know what -#*i might possibly be.

Assuming I'm correct that $- are flags passed to the script, I'm thinking ${-#*i} must also be flags but I don't really have a clue.

Can someone please explain. Links with list of these special variables would be appreciated too.

Thanks in advance.

like image 789
Jistanidiot Avatar asked Dec 27 '22 21:12

Jistanidiot


1 Answers

It is checking if the current shell is an interactive shell or not.

Presence of -i in the $- variable (which contains the list of flags passed to the shell) is one way of checking for interactive vs non-interactive shell. See here for a list of internal shell variables including $-

like image 112
kjp Avatar answered Jan 05 '23 21:01

kjp