shell学习笔记

美妙的shell


   tar cvf - * | ( cd  /dest/dir && tar xvfp -)       #会遗漏隐藏文件

   find . -depth | xargs tar cvf -  | ( cd /dest/dir && tar xvfp - )    

发邮件:
#!/bin/bash
# script to send simple email
# email subject
SUBJECT="SET-EMAIL-SUBJECT"
# Email To ?
EMAIL="[email protected]"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
awk '$2 == "waptest.taobao.com" { print $0 }' /etc/host
awk '$2 ~ "waptest*" { print $0 }' /etc/hosts
   
忽略文件仲的空行和注释行
sed -e "s/#.*//g" /etc/hosts | awk '{if(length!=0) print $0}'
egrep "desk|admin" /etc/hosts === grep -P "desk|admin" /etc/hosts


  行编辑命令
wuzhong@TAOBAOWDS46:~/bin$ more ed.script g/^k/s/k.*/kkkkkkkkk/g w q wuzhong@TAOBAOWDS46:~/bin$ ed -s txt < ed.script  
#!/bin/bash set -x TO_STRING=123 FROM_STRING=^k FROM_STRING2=k.* echo $TO_STRING $FROM_STRING $FROM_STRING2 #cat ed.script | while read a_line #do # eval echo $a_line 变量替换 #done | more echo "g/$FROM_STRING/s/$FROM_STRING2/$TO_STRING/g" > tmp echo "w" >> tmp echo "q" >> tmp ed -s txt < tmp 
ed -s txt << EOF g/$FROM_STRING/s/$FROM_STRING2/$TO_STRING/g w q EOF 


       
CAT 格式化输出
wuzhong@TAOBAOWDS46:~/bin$ more example_cat.sh 
#!/bin/bash
AAA=AAAaaaaaa
cat > tmp << TAG
  111111111
  2222222222
  333333333
  $wtm_daily_host
  $AAA
TAG

      
14 FILE_PATH=$1
15 FILE_NAME =$(basename $1)
 'expr  $a + 1'  ===   $(($a+1))


在shell中使用数组


shell语法 :

你可能感兴趣的:(html,.net,Blog,bash)