文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>学习bash第五章 学习笔记

学习bash第五章 学习笔记

时间:2008-04-12  来源:dracohan

1.

pushd()
{
    dirname=$1
    if cd ${dirname:?"missing dirctory name."}
    then DIR_STACK="$dirname ${DIR_STACK:-$PWD' '}"
         echo $DIR_STACK
    else

         echo still in $PWD
    fi
}

 

2.

#builtin用于确保调用内部命令
cd()
{
    builtin cd "$@"
    echo "$OLDPWD-->PWD"
}

 

3.

#返回1
cd baddir
echo $?
#返回0
cd gooddir
echo $?

 

4.

popd()
{
    if [-n "$DIR_STACK"]
    then DIR_STACK=${DIR_STACK#* }

         cd ${DIR_STACK%% *}
         echo "PWD"
    else
         echo "stack empty, still in $PWD"
}

5.

IFS=:
for dir in $PATH do
   if [-z "$dir"];then dir=.;fi
   if ![-e"$dir"];then
      echo "$dir doesn't exsit"
   elif ![-d"$dir"];then
      echo "$dir is not a dir"
   else
      ls -ld $dir
  fi
done

6.

recls()
{
  singletab="\t"
  for tryfile in "$@" do
      echo $tryfile
      if[-d "$tryfile"]
        thisfile=$tryfile
        recdir $(command ls $tryfile)
       fi
   done
   unset dir singletab tab
}

 

 

recdir()
{
    tab=$tab$singletab
    for file in "$@";do
        #-e使\n解释为换行符
        echo -e $tab$file
        thisfile=$thisfile/$file
        if [-d "$thisfile" ];then
           recdir $(command ls $thisfile)
        fi
        thisfile=${thisfile%/*}
    done
    tab=${tab%\t}
}

 

7.

cd()
{
    case "$#" in
        0|1) builtin cd $1
        2 ) newdir=${echo $PWD| sed -e "s:$1:$2:g"}
            case $newdir in
                 $PWD) echo"bash:cd:badsubstitution" >&2;
                  return 1;;
                  *) builtin cd "$newdir"
             esac;
        *) echo "bash:cd:wrongarg count" 1>&2;return 1;;
  esac
}

 

8.

selecttd()
{
    PS3='directory? '
    dirstack=" $DIR_STACK"
    select selection in $dirstack;do
      if .....
      else
      fi
    done
}

 

9.

until cp $1 $2;do
    echo"Attempt to copy failed.waiting..."
    sleep 5
done

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载