#!/bin/bash# #获取目标目录target =/mnt/sysroot# Command copy function cmndcopy () { # If the order does not exist,return 1 if ! which $1 & > /dev/null; then return 1 fi #获取命令决定路径 cmnd=$ (which -- skip-alias $1) #获取命令目录名 cmndpath=$ (dirname $cmnd) #判断命令目录名是否存在, no, create [ - d $target/$cmndpath ] | | mkdir -p $target/$cmndpath #判断命令是否存在, no, then copy [ -e $ target/$CMND ] | | cp $cmnd $target/$cmnd return 0}# Library file copy function libcopy () { #获取库文件目录名 libpath=$ (dirname $1) #判断库文件目录名是否存在, no, create [ -d $target/$libpath ] | | mkdir -p $target/$libpath #判断库文件是否存在, no, then COPY        [ -E $target/$1 ] | | cp $1 $target/$1} #提示输入要copy的命令, quit can exit read -p "Plz enter a command ( quit for quiting): " binary# loop Copy command,Encounter the Quit character launch loop until [ $binary == "quit" ]; do #调用命令copy函数 cmndcopy $binary #保存命令copy函数返回值 retval=$? #如果返回值等于0, then if [ $retval -eq 0 ]; then #获取命令库文件的路径 binary=$ (which --skip-alias $binary) #循环取出库文件路径 for lib in $ (ldd $binary | grep -o "/[^[:space:]]*lib[^[:space:]]*"); do #调用库文件copy函数 libcopy $lib done #如果返回值不为0, then else #提示命令输入错误 and can re-enter read -p "$binary is not correct, plz enter again (quit for quiting): " binary #并提前结束本轮循环 continue fi # Prompt again for the command to copy, quit can exit read -p "plz enter A command (quit for quiting): " binarydone
This article is from the "Wangjian it road!" "Blog, be sure to keep this provenance http://asherwang.blog.51cto.com/11255017/1930334
Copy command and library file to/mnt/sysroot/directory shell script