0
我有一个名为find:如何在-exec指令中使用找到的路径?
~/DOMAIN1.de/bin/dbdeploy.php
~/DOMAIN2.de/bin/dbdeploy.php
~/DOMAIN3.de/bin/dbdeploy.php
我想使用相同的参数运行所有这些十几文件。 我的bash脚本读取:
cd ~
find . -maxdepth 1 -type d -name "*\.de" -exec php56 bin/dbdeploy.php "$1" "$2" \;
然而,考虑到高管的路径似乎并没有被相对于发现的子目录,而是我的PWD:
$ bash -x ./.dbpush "some argument"
+ cd ~
+ find . -maxdepth 1 -type d -name '*\.de' -exec php56 bin/dbdeploy.php 'some argument' ';'
Could not open input file: bin/dbdeploy.php
Could not open input file: bin/dbdeploy.php
Could not open input file: bin/dbdeploy.php
如何使用被发现路径在-exec指令中?
不回答你的问题,但实现相同的目标,使用你的shell而不是外部工具'find':'for d in〜/ *。de/bin/dbdeploy.php;做php56“$ d”“$ 1”“$ 2”; done'。 –
谢谢,@gniourf_gniourf!我用搜索整个文件名的想法,并摆脱那些“文件不存在”的错误: 找到。 -type f -wholename“* \。de/bin/dbdeploy.php”-exec php56 {}“$ 1”“$ 2”\; –
就你而言,我仍然相信shell比'find'更优越(并且它更具可移植性,因为你使用的是非标准(GNU)扩展)。 –