[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bash Problems & Suggestions
From: |
Christopher Buckley |
Subject: |
Bash Problems & Suggestions |
Date: |
Thu, 19 Feb 2004 15:09:03 -0800 (PST) |
I'm a newbie to Linux, although not computers. I've
been reading up on bash to see how it works, and
experimenting. I've found parts of the manpage to be
somewhat difficult to comprehend, and have included
some alternative materials. I hope I've understood it
right.
In the meantime, I'm having a problem with a
particular script giving unexplainable results.
I've added the statement ". /bash/all.envir" to the
end of my /etc/profile. The script runs but fails in
the tests of "$LOGNAME". It keeps returning
configurations for "root" even when I logon as "cpmb".
I can't figure out why. Can you help?
ATTACHMENTS ARE:
all.envir
bashupdates.txt
Thanks
Christopher
__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools
# NAME: all.envir
#
# NOTES: This file should be used only for global configurations
# Do NOT use this one for user specific configurations
# Use either ~/.bash_profile or ~/.profile for user
specific configurations
#
#--------------------------------------------------------------------------------------
if [ -n "$DEBUG_CALLS" ]; then
if [ "$0"=="-bash" ]; then
echo BEGIN: all.envir
else
echo BEGIN: $0
fi
fi
#---------------------------------
# BEGIN:
#---------------------------------
# Non-interactive shells dump PS1 on startup
# You should reset PS1 for interactive shells
# FIRST - Set local or global variables
# PATH should only include required paths
PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin/X11
if [ "${LOGNAME}"=="root" ]; then
echo Root Paths
PATH=/sbin:${PATH}
if [ -d /bash ]; then
PATH=/bash:${PATH}
fi
else
echo User Paths
if [ -d ~/bash ]; then
PATH=${PATH}:~/bash
fi
if [ -d ~/bin ]; then
PATH=${PATH}:~/bin
fi
if [ -d ~/sbin ]; then
PATH=${PATH}:~/sbin
fi
if [ -d ~/man ]; then
MANPATH=${MANPATH}:~/man
fi
fi
# SECOND - Set local or global modes
mesg n
umask 022
VERSION=`uname -r`
# THIRD - Are we interactive???
if [ "${PS1}" ]; then
# Setup prompt and common attributes
PS1="\n\w\t\n${LOGNAME}@\H"
if [ "$LOGNAME"=="root" ]; then
echo Root Configs
PS1="${PS1}$ "
alias dir='vdir -a | more'
alias ls='ls -a | more'
else
echo User Configs
PS1="${PS1}# "
# Directory listing colors
eval `dircolors`
alias dir='vdir | more'
alias ls='ls --color=auto | more'
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
fi
fi
# FOURTH - Export any variables to sub-shells
export DEBUG_CALLS DEBUG_FLOW PATH PS1 VERSION
#---------------------------------
# EXTRAS:
#---------------------------------
# Check full filename used to invoke
#if [ "$BASH" ]; then
# PS1='\u@\h:\w\$ '
#else
# if [ "`id -u`" -eq 0 ]; then
# PS1='# '
# else
# PS1='$ '
# fi
#fi
# If this is an xterm set the title to user@host:dir
#case $TERM in
#xterm*)
# PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
# ;;
#*)
# ;;
#esac
# Enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc).
#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
#fi
#---------------------------------
# ERROR HANDLERS:
#---------------------------------
#---------------------------------
# END:
#---------------------------------
# That's all folks!
if [ -n "$DEBUG_CALLS" ]; then
if [ "$0"=="-bash" ]; then
echo END: all.envir
else
echo END: $0
fi
fi
Bash uses a white space separated syntax.
ALL elements must have separators
EXAMPLE:
if ["$LOGNAME"=="root"]; then
will NOT work. it must be:
if [ "$LOGNAME"=="root" ]; then
INVOCATION & EXIT
Execution
1) Directory & Script must have execute access rights
2) PATH must include script folder or use /<path> prefix
3) Type the name of the script or . name.
NOTE: Preceeding the name with . will cause it to be sourced.
EXAMPLES:
/bash/myscript
. myscript
Exit Status
Bash's exit status is the exit status of the last
command executed in the script. If no commands are
executed, the exit status is 0.
Invocation - Files
/bin/bash
The bash executable
/etc/profile
The systemwide initialization file, executed for
login shells
~/.bash_profile
The personal initialization file, executed for
login shells
~/.bashrc
The individual per-interactive-shell startup file
~/.bash_logout
The individual login shell cleanup file, executed
when a login shell exits
~/.inputrc
Individual readline initialization file
Invocation Modes:
A LOGIN shell is one which is started by specifying the
--login option, or is one in which argument zero (the first
argument following the options list) begins with a - character.
A NON-LOGIN shell is one which may be started as a subshell or
CHILD of an existing shell. It may be interactive or non-
interactive depending upon the calling options.
An INTERACTIVE shell is one which is started
1) with its standard input and output both connected
to terminals (as determined by isatty(3))
2) may have been started with the -i option
3) and was not started using the -c option
4) and was not started by specifying any [file], nor
any other non-optional arguments
If bash is interactive, PS1 will be set and the parameter $-
will include "i", allowing a shell script or a startup file
to test bash's state.
A NON-INTERACTIVE shell is one which is started with its
standard input redirected (to a file or device) and output
may or may not be connected to terminals. It is generally a
a NON-LOGIN shell intended to run to completion.
Invocation Behaviour:
The following paragraphs describe how bash executes its
startup files. If any of the files exist but cannot be
read, bash reports an error. Tildes are expanded in file
names as described below under Tilde Expansion in the
EXPANSION section.
When bash is invoked as a LOGIN shell, either interactively
or as a non-interactive shell using the --login option, it
attempts to read and and execute commands from specific
files, according to the following hierarchy:
1) /etc/profile
2a) ~/.bash_profile
2b) ~/.bash_login
2c) ~/.profile
Note that for 2a, 2b, and 2c, bash will read commands only
from the FIRST FILE that exists and is readable. This auto
configuration behaviour may be inhibited if the option
--noprofile is specified when the shell is initiated.
When a LOGIN shell exits, bash attempts to read and execute
commands from the file ~/.bash_logout, if it exists.
When a NON-LOGIN shell is started, regardless of interactivity
bash attempts to read and execute commands from ~/.bashrc,
if that file exists. This may also be inhibited by using
the --norc option. The --rcfile file option will force bash to
read and execute commands from [file] instead of ~/.bashrc.
- Bash Problems & Suggestions,
Christopher Buckley <=