0

I'm writing a script in bash. I invoke it with

find *.zip -type f -exec ./myscript.sh {} \;

At the top of my script I invoke another script like this:

#!/bin/bash
. ticktick.sh

I get the following error

.: ticktick.sh: file not found

If I invoke the script like this

./myscript.sh somefile.zip

it works If I put the ticktick.sh script in my path in another directory it breaks, so that isn't an option. Is there some special kind of context that scripts called with a find have? I'm obviously new to BASH scripting. Any help would be appreciated

4

1 回答 1

1

我认为有2个问题。

1.:如果要搜索当前目录下的所有zip文件,必须编写如下命令

find . -type f -name *.zip -exec ...

2.:你在 myscript.sh 之前执行 ./ 。所以 myscript.sh 必须在当前工作目录中。如果您的脚本位于 /home/jd/ 并且您从 /home/ 执行它,您的 myscript.sh 将找不到。首先,您必须确定文件的目录:

install_path=$(dirname $(readlink -f $0))

所以你完整的 find 命令是:

find . -type f -name *.zip -exec $install_path/myscript.sh {} \;

myscript.sh 文件必须与 ticktick.sh 位于同一目录中

于 2012-08-13T21:43:20.673 回答