Monday, November 4, 2013

Syntax Questions in /etc/profile file

www.unixbabuforum.inI read /etc/profile file but didn't understand below codes: 
for i in /etc/profile.d/*.sh ; do 
if [ -r "$i" ]; then 
if [ "${-#*i}" != "$-" ]; then 
. "$i" 
. "$i" >/dev/null 2>&1 
What is restricted shell? 
What is ${-#*i} and $- ? 

www.unixbabuforum.inThe restricted shell (usually 'rsh') is used for network logins. It severely restricts the available operations, changing directory, etc.. 

The shell variable $- "dollar-minus" is the currently set shell options (i had to look it up) 
shell allows four substitutions of a variable:


Where two tokens do a LONG trim, one a SHORT trim, sharps (#) from the left, percent (%) from the right. ... So, using a single #, 

${-#*i} trims letters from the left including the "i" 

empty.$ echo $-
empty.$ echo ${-#*i}


so, your shell is "source"ing readable files in /etc/profile.d/*.sh and when your shell settings don't have arguments to the left of the "i" flag, then you are dumping standard out and error to the bit bucket. 

e.g. one of my favorite tricks, when handling TXT files, filtering into other files:

     do_something $stem.txt > $stem.out 2> $stem.err

www.unixbabuforum.inDepend on Login shell ,/etc/profile decides to execute some scripts. 

Check /etc/profile.d , you can find many files with different extensions. 

If your Login shell is csh, , profile will executes *.csh files.


Post a Comment

Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM