我正在尝试编写一个bash脚本,上面写着:
移动除.gitignore,.git之外的每个文件和文件夹。然后提示文档文件夹(你想要这个软件包的文档文件夹吗?),如果没有 - 不要移动,如果是,移动。
我不知道我正在做什么,因为我是新手来编写脚本,到目前为止我所拥有的只是:
#!/bin/bash
clear
if [ -d "vender/adamb.balan/aisis-core/" ]
// do soemthing
fi
答案 0 :(得分:0)
你可以这样做:
read resp
if [ $resp = 'y' -o $resp = 'Y' ]; then
# do your mv.
fi
但它显然已被弃用...... http://wiki.bash-hackers.org/syntax/ccmd/conditional_expression
答案 1 :(得分: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(当你满意的时候,所有这些都按照要求工作)
答案 2 :(得分:-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