亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 3094 | 回復: 13
打印 上一主題 下一主題

UNIX SHELL 實例精解學習貼(每天2例) [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-03-02 22:35 |只看該作者 |倒序瀏覽
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文件遍歷,全部執(zhí)行一邊,如果這個文件的權限為可執(zhí)行的話

unset i #


ex 13.05
# .bash_profile
# The file is sourced by bash only when the user logs on.
#source讓此文件在當前進程內執(zhí)行
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi#-f 在這里判斷~/.bashrc時候是一個文件

# User-specific environment and startup programs

PATH=$PATHHOME/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:此貼用于個人學習,歡迎討論并指出錯誤。


  1. #!/bin/bash
  2. # Gnu bash versions 2.x
  3. # The Party Program--Invitations to friends from the
  4. # "guest" file
  5. #guestfile=~/shell/guests
  6. guestfile=./guests
  7. if [[ ! -e "$guestfile" ]]
  8. then
  9. printf "${guestfile##*/} non-existent"
  10. exit 1
  11. fi
  12. export PLACE="Sarotini's"
  13. (( Time=$(date +%H) + 1 ))
  14. declare -a foods=(cheese crackers shrimp drinks '"hot dogs"'
  15.                   sandwiches)  
  16.    declare -i  n=0
  17. for person in $(cat $guestfile)
  18. do
  19. if  [[ $person == root ]]
  20. then
  21.   continue
  22. else
  23.   # Start of here document
  24.   mail -v -s "Party" $person <<- FINIS
  25.   Hi $person! Please join me at $PLACE for a party!
  26.   Meet me at $Time o'clock.
  27.   I'll bring the ice cream. Would you please bring
  28.   ${foods[$n]} and anything else you would like to eat?
  29.   Let me know if you can make it.
  30.          Hope to see you soon.
  31.                           Your pal,
  32.                           ellie@$(hostname)
  33.   FINIS
  34.   n=n+1  
  35.   if (( ${#foods[*]} ==  $n ))
  36.   then
  37.      declare -a foods=(cheese crackers shrimp drinks
  38.                        `"hot dogs"` sandwiches)
  39.             n=0
  40.   fi
  41. fi
  42. done  
  43. printf "Bye..."
復制代碼












學習結果展示貼:持續(xù)改進。。。。
#!/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 編輯 ]

論壇徽章:
0
2 [報告]
發(fā)表于 2009-03-02 23:19 |只看該作者
學習了,謝謝,這就是傳說中的UNIX SHELL 實例精解書中的實例???

論壇徽章:
0
3 [報告]
發(fā)表于 2009-03-03 00:32 |只看該作者

回復 #1 wxws2002 的帖子

受用

論壇徽章:
0
4 [報告]
發(fā)表于 2009-03-03 07:11 |只看該作者
看得有點暈,排版有待加強

論壇徽章:
9
2015亞冠之阿爾納斯爾
日期:2015-09-10 16:21:162015亞冠之塔什干火車頭
日期:2015-07-01 16:23:022015年亞洲杯之巴勒斯坦
日期:2015-04-20 17:19:46子鼠
日期:2014-11-13 09:51:26未羊
日期:2014-08-28 18:13:36技術圖書徽章
日期:2014-02-21 09:30:15酉雞
日期:2014-01-14 11:12:49天蝎座
日期:2013-12-09 17:56:53平安夜徽章
日期:2015-12-26 00:06:30
5 [報告]
發(fā)表于 2009-03-03 08:26 |只看該作者
不錯,實際的例子,
/etc/init.d/下面也有很多

論壇徽章:
0
6 [報告]
發(fā)表于 2009-03-03 10:20 |只看該作者
汗啊,我今天剛好看到這本書的這一頁。。。
難怪看得很眼熟

論壇徽章:
0
7 [報告]
發(fā)表于 2009-03-04 22:48 |只看該作者

今天學了一下Sed

例子很多,但是書里面的例子還是挺淺的,還是需要多在版上學習學習!
一直有個疑問

sed -n  '/[0-9][0-9]$/' datafile 為什么回的結果為空呢?

datafile:
northwest        NW        Joel Craig        3.0        .98        3        4
western        WE        Sharon Kelly        5.3        .97        5        23
southwest        SW        Chris Foster        2.7        .8        2        18
southern        SO        May Chin        5.1        .95        4        15
southeast        SE        Derek Johnson        4.0        .7        4        17
eastern        EA        Susan Beal        4.4        .84        5        20
northeast        NE        TJ Nichols        5.1        .94        3        13
north        NO        Val Shultz        4.5        .89        5        9
central        CT        Sheri Watson        5.7        .94        5        13


我的想法是末尾為2個數字的應該都能匹配上?

論壇徽章:
0
8 [報告]
發(fā)表于 2009-03-05 07:20 |只看該作者

回復 #7 wxws2002 的帖子

你cat -A datafile

論壇徽章:
0
9 [報告]
發(fā)表于 2009-03-05 09:27 |只看該作者
cat -A datafile
northwest^INW^ICharles Main^I^I3.0^I.98^I3^I34^M$
western^I^IWE^ISharon Gray^I^I5.3^I.97^I5^I23^M$
southwest^ISW^ILewis Dalsass^I^I2.7^I.8^I2^I18^M$
southern^ISO^ISuan Gray^I^I5.1^I.95^I4^I15^M$
southeast ^ISE^IPatricia Hemenway^I4.0^I.7^I4^I17^M$
eastern^I^IEA^ITB Savage^I^I4.4^I.84^I5^I20^M$
northeast ^INE^IAM Main Jr.^I^I5.1^I.94^I3^I13^M$
north^I^INO^IMargot Weber^I^I4.5^I.89^I5^I 9^M$
central^I^ICT ^IAnn Stephens^I^I5.7^I.94^I5^I13^M$



sed -n  '/[0-9][0-9].$/p' datafile 就可以,難道是^M?問題是用編輯器是刪不掉這個換行符的。


cat -A data
1234 4567 2334$
2333 3333$
21122 a v ds ss aa   

自己變了個文件,沒有^M,看來這個是windows下編輯造成的。

[ 本帖最后由 wxws2002 于 2009-3-5 09:38 編輯 ]

論壇徽章:
1
處女座
日期:2014-12-23 17:59:27
10 [報告]
發(fā)表于 2009-03-05 11:15 |只看該作者
sed -n  '/[0-9][0-9]$/' datafile

這樣的話, 不管你什么樣的模式 結果都為空.
我這里甚至報錯.
sed: -e expression #1, char 13: missing command
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯網協會會員  聯系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP