Copy command and library file to/mnt/sysroot/directory shell script

Source: Internet
Author: User
Tags file copy

#!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.