unlink_and_cp.sh

上一篇 / 下一篇  2018-03-06 22:15:45 / 个人分类:Shell

#!/bin/bash -


##################################################
# This scripts is uesed to unlink the file,
# and copy the linked file to local dir.
#################################################


# Function Usage
Usage () {
echo "[Usage]: $0 file.link (for single file)" >&2
echo "[Usage]: $0 * (for all files)" >&2
}


# Function UnlinkFile
UnlinkFile () {
if test -h $1
then
cp $1 ${1}.old
unlink $1
mv ${1}.old $1
printf "[Info]: %20s unlink done!!\n" $1
else
printf "[Info]: %20s isn't a link file!!\n" $1
fi
}




file=
verbose=
quiet=
long=

if $# -eq 0
then
echo "[Warning] Please add some file names or (*) ." >&2
echo "[Warning] Please refer to below comments for more infomation." >&2
Usage
fi

# Main Function
while [ $# -gt 0 ]
do
case $1 in
-f) file=$2
shift 2
;;
-v) verbose=ture
quiet=
shift
;;
-q) quiet=ture
verbose=
shift
;;
-h | -help) Usage
exit 1
;;
--) shift
#break
;;
-*) echo $0:$1 : unrecognised option >&2
shift
;;
*) UnlinkFile $1
shift
;;
esac
done




#echo $*
#for i in $*
#do
# if test -h $i
# then
# cp $i ${i}_1
# unlink $i
# mv ${i}_1 $i
# printf "[Info]: %20s unlink done!!\n" $i
# else
#
# printf "[Info]: %20s isn't a link file!!\n" $i
# fi
#done


#while [ $# -gt 0 ]
#do
# if test -h $i
# then
# ehco "$i"
# mv $i ${i}_1
# unlink $i
# mv ${i}_1 $i
# else
# echo "$i isn't a link!!"
# fi
# shift
#done



TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2018-07-08  
1234567
891011121314
15161718192021
22232425262728
293031    

数据统计

  • 访问量: 5893
  • 日志数: 36
  • 建立时间: 2018-01-19
  • 更新时间: 2018-06-23

RSS订阅

Open Toolbar
博聚网