-2

我正在尝试编写一个 bash 脚本,上面写着:

移动每个文件和文件夹,除了:.gitignore、.git。然后提示文档文件夹(你想要这个包的文档文件夹吗?),如果没有 - 不要移动,如果是,移动。

我不知道自己在做什么,因为我是 bash 脚本的新手,到目前为止我所拥有的只是:

#!/bin/bash
clear

if [ -d "vender/adamb.balan/aisis-core/" ]
  // do soemthing
fi
4

3 回答 3

0
#!/bin/bash

source_folder=$1       
project=$2
dest_folder=$3

if [[ $# -lt 3 ]]; then
    echo "$0 source_folder project dest_folder"
    echo "------------------------------------"
    echo "$0 /home/projects project1 /var/tmp"
    echo "This will cd into /home/projects tar up required from folder project1"
    echo "and extract to a folder called project1 folder in /var/tmp"
    exit 1;
fi


echo "Do you want to move Documents (Y/N) ?"
read resp
addon=" --exclude=.git --exclude=.gitignore "
if [ $resp == 'n' ] || [ $resp == 'n' ]; then     
    addon=$addon"--exclude=Documents"
fi
(cd $source_folder; tar -cvzf $addon - $project) | (cd $dest_folder; tar -xvzf -)
# remove folder when and if you are happy with the dest_folders $project content
# rm -rf $source_folder/$project

你可以试试上面的东西

与其移动它,不如将其去皮并同时将其提取到新的目标文件夹中,然后您可以 rm -rf $source (当您满意时,一切都按要求工作)

于 2013-09-20T18:50:22.103 回答
0

你可以这样做:

 read resp
 if [ $resp = 'y' -o $resp = 'Y' ]; then  
    # do your mv.
 fi

但它显然已被弃用...... http://wiki.bash-hackers.org/syntax/ccmd/conditional_expression

于 2013-09-20T18:44:20.070 回答
-1

尝试这个,

     #!/bin/bash
     echo Do you want to move (Y/N) ?
     read resp
     echo "$resp"
     if [ [ $resp = 'y' ] || [ $resp = 'Y'] ]; then  
        mv <source dir name>/* <destination dir name>/ 
     fi
于 2013-09-20T18:34:51.673 回答