我想要一个将目录更改为file.sh所在的目录的脚本。
然后,我想从另一个位置复制文件,假设 var2 ,将文件复制到当前的dir,那将是 var 。
然后我想在文件中进行一些解压缩和删除行,这些行在 var
我尝试了以下操作,但是我的语法不正确。有人可以建议吗?
#!/bin/bash
# Configure bash so the script will exit if a command fails.
set -e
#var is where the script is stored
var="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd";
#another dir I want to copy from
var2 = another/directory
#cd to the directory I want to copy my files to
cd "$var" + /PointB
#copy from var2 to the current location
#include the subdirectories
cp -r var2 .
# This will unzip all .zip files in this dir and all subdirectories under this one.
# -o is required to overwrite everything that is in there
find -iname '*.zip' -execdir unzip -o {} ;
#delete specific rows 1-6 and the last one from the csv file
find ./ -iname '*.csv' -exec sed -i '1,6d;$ d' '{}' ';'
这里有一些错误:
# no: var="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd";
var=$(cd "$(dirname "$0") && pwd)
$()中的内容在子壳中执行,因此" PWD"必须在您拥有的" CD" -ED的外壳中执行。
# no: var2 = another/directory
var2=another/directory
=不能周围有空白。
# no: cd "$var" + /PointB
cd "$var"/PointB
shell不是javaScript,字符串contatenation没有单独的操作员
# no: cp -r var2 .
cp -r "$var2" .
需要$以获取变量的值。
# no: find -iname '*.zip' -execdir unzip -o {} ;
find . -iname '*.zip' -execdir unzip -o {} ;
将起始目录指定为第一个查找的参数。