- 论坛徽章:
- 0
|
2009-03-02
ex 13.04
# /etc/profile
# Systemwide environment and startup programs
# Functions and aliases go in /etc/bashrc
PATH="$PATH:/usr/X11R6/bin" #设置SHELL查找命令的路径
PS1="[\u@\h \W]\\$ " #这里设置\u 是用户名 \h 是机器名 \W为当前目录 [username@chinaunix shell_dir]$
ulimit -c 1000000 #如果此文件CORE DUMP的时候最大的CORE文件大小为1000,000bytes
if [ `id -gn` = `id -un` -a `id -u` -gt 14 ]; then #id -gn 取groupname,id -un 取username,id-u 取用户的ID。
umask 002
else
umask 022
fi
USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
HISTFILESIZE=1000
export PATH PS1 HOSTNAME HISTSIZE HISTFILESIZE USER LOGNAME MAIL
for i in /etc/profile.d/*.sh ; do
if [ -x $i ]; then
. $i
fi
done # 对/etc/profile.d/*.sh下面的sh文件遍历,全部执行一边,如果这个文件的权限为可执行的话
unset i #
ex 13.05
# .bash_profile
# The file is sourced by bash only when the user logs on.
#source让此文件在当前进程内执行
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi#-f 在这里判断~/.bashrc时候是一个文件
# User-specific environment and startup programs
PATH=$PATH HOME/bin
ENV=$HOME/.bashrc # or BASH_ENV=$HOME/.bashrc
USERNAME="root"
export USERNAME ENV PATH
mesg n #The mesg command is executed with the n option, disallowing others to write to the terminal
if [ $TERM = linux ]
then
startx # Start the X Window system
fi
Note1:注意if then fi的两种写法。
Note2:此贴用于个人学习,欢迎讨论并指出错误。
- #!/bin/bash
- # Gnu bash versions 2.x
- # The Party Program--Invitations to friends from the
- # "guest" file
- #guestfile=~/shell/guests
- guestfile=./guests
- if [[ ! -e "$guestfile" ]]
- then
- printf "${guestfile##*/} non-existent"
- exit 1
- fi
- export PLACE="Sarotini's"
- (( Time=$(date +%H) + 1 ))
- declare -a foods=(cheese crackers shrimp drinks '"hot dogs"'
- sandwiches)
- declare -i n=0
- for person in $(cat $guestfile)
- do
- if [[ $person == root ]]
- then
- continue
- else
- # Start of here document
- mail -v -s "Party" $person <<- FINIS
- Hi $person! Please join me at $PLACE for a party!
- Meet me at $Time o'clock.
- I'll bring the ice cream. Would you please bring
- ${foods[$n]} and anything else you would like to eat?
- Let me know if you can make it.
- Hope to see you soon.
- Your pal,
- ellie@$(hostname)
- FINIS
- n=n+1
- if (( ${#foods[*]} == $n ))
- then
- declare -a foods=(cheese crackers shrimp drinks
- `"hot dogs"` sandwiches)
- n=0
- fi
- fi
- done
- printf "Bye..."
复制代码
学习结果展示贴:持续改进。。。。
#!/bin/bash
#####################Main Part##############################
if [ id -un!="Cuser" ];then
checkCuser()
else
umask 002
sourceAll()
fi
mesg n
ulimit -c 1000000
if [ $SHELL!="Bash" ]
then
bash # Change to Bash
fi
###########################################################
#####################Function set #########################
function checkCuser() {
echo " lease change to Cuser,use \"su -\""
}
function sourceAll() {
for i in ./scripts/*.sh; do
if [ -x $i ];then
. $i
fi
done
}
###########################################################
[ 本帖最后由 wxws2002 于 2009-3-3 21:38 编辑 ] |
|