#!/bin/bash
# function:cp command and lib funciton
N=/mnt/sysroot
LDD () {
which $1 &>/dev/null
RETVAL=$?
if [ $RETVAL -ne 0 ];then
echo "The $1 is not esxits."
return $RETVAL
fi
# bring out $1
DIR=`which $1 |grep -o "/.*"`
# bring out before
DIR1=`which $1 |grep -o "/.*" | sed "s@\(.*\)$1@\1@g"`
[ -d $N$DIR1 ] || mkdir -p $N$DIR
[ $? -eq 0 ] && echo "Directory create sucessful." || return 10
[ -e $N$DIR ] || cp -fp $DIR $N$DIR
[ $? -eq 0 ] && echo "$DIR command copy sucessful." || return 11
# Bring out lib file
LDDDIR=`ldd $DIR |grep -o "/[^[:space:]]*"`
for I in $LDDDIR;do
# Bring out lib dir
LDDDIR1=`echo $I |sed "s@\(.*\)/[^/]*@\1@g"`
[ -d $N$LDDDIR1 ] || mkdir -p $N$LDDDIR1 &>/dev/null
[ -e $N$I ] || cp -fp $I $N$LDDDIR1
done
}
while true;do
read -p "Do you want copy command:(Y/n) " ANSWER
if [ "$ANSWER" = "Y" -o "$ANSWER" = "y" ];then
read -p "which your copy command: " COM
LDD $COM
else
echo "You do not copy command."
exit 1
break
fi
done
本文出自 “fish” 博客,请务必保留此出处http://seeds.blog.51cto.com/1501815/1396134