lgxqf  

将标准输出重定向到一个文件的同时并在屏幕上显示

 一、标准输出+标准错误

运行命令command同时保存到文件名为logfile:   <command> 2>&1 | tee <logfile>

例:make 2>&1 | tee ~/makelog.txt

注释:管道的作用为把一个进程的标准输出作为另一个进程的标准输入。2>&1是把标准错误重定向到标准输出的副本一起输出。上面的命令,把标准输出和标准错误都输出作为tee命令的标准输入,tee的作用为把标准输入的内容拷贝到文件,并输出。

二、按指定的字符串截取
1、第一种方法:
${varible##*string} 从左向右截取最后一个string后的字符串
${varible#*string}从左向右截取第一个string后的字符串
${varible%%string*}从右向左截取最后一个string后的字符串
${varible%string*}从右向左截取第一个string后的字符串
“*”只是一个通配符可以不要


Shell 参数选项

-n 只读取shell脚本,但不实际执行。可用于测试shell脚本是否存在语法错误,但不会实际执行命令
-x 进入跟踪方式,显示所执行的每一条命令
-c "string" 从strings中读取命令

如何改变Shell的颜色

cNO="\033[00m"     #还原
cFR="\033[01;31m"  #红色前景


cFG="\033[01;32m"  #绿色前景
cFY="\033[01;33m"  #黄色前景
cFB="\033[01;34m"  #兰色前景
cFM="\033[01;35m"  #艳红前景
cFC="\033[01;36m"  #浅兰前景
cFL="\033[01;37m"  #亮白前景

cBR="\033[01;41m"  #红色背景
cBG="\033[01;42m"  #绿色背景
cBY="\033[01;43m"  #黄色背景
cBB="\033[01;44m"  #兰色背景
cBM="\033[01;45m"  #艳红背景
cBC="\033[01;46m"  #浅兰背景
cBL="\033[01;47m"  #亮白背景

#用法举例:echo -e "$cFG 前景 $cBG 背景 $cNO 全部复原"

#递归删除目录下的所有名称为CVS的文件夹

#!/bin/bash

CVSDIR="/root/android/cupcake/external/OMA"
CVSD="/root/CVS/omaRoot"

function deletecvs()
{
for dir in $1/*
    do

    if [ -d "$dir" ];then
        if echo "$dir" | grep "CVS$" ;then

            echo "rm -rf $dir"
            #rm -rf $dir    
        else
            deletecvs "$dir"
        fi
    fi

done
}


function dostounix()
{
    for dir in $1/*

     do
        if [ -d "$dir" ]; then
            dostounix "$dir"
        else
            if file $dir | grep "text" ; then
                echo "dos2unix $dir"
                dos2unix $dir
            fi        
        fi

    done
}

if [ -n "$1" ]; then

    read -p "Peform deleting CVS dir for CVS code?:(y/n)" result

    if [ $result = "y" ] || [ $result = "Y" ] ; then
        deletecvs $CVSD

    fi
else
    read -p "Please input dir:"  dosdir    
    dostounix "$dosdir"

fi

Linux访问windows共享文件夹

    sudo mount //10.86.7.116/share /mnt/myshare -o username=Ma.yi@irdeto.com,password=ma.yi

    //10.86.7.116/share 是windows主机的共享目录   username password是windows用户账号和密码

posted on 2009-11-17 16:23  Justin_Ma  阅读(459)  评论(0)    收藏  举报