我正在使用 Zend CRUD 生成器,我必须用每个字段的表单代码替换 $targetForm 文件中的单词“test”。
field[0]="foo"
field[1]="bar"
textareafield='$'"acme_en = new Utils_Form_Element_Textarea('acme_en',array('langblock'=>'en', 'isWysiwyg' => true));
"'$'"this->addElement("'$'"acme_en);
"'$'"this->addElement('textarea','acme_fr', array( 'label'=>__('acme'), 'langblock'=>'fr', 'isWysiwyg' => true, 'altLangElem' => "'$'"acme_en));"
for ((i=0; i<${#field[@]}; i++));
do
formfield[$i]=$textareafield
formfield[$i]=${formfield[$i]//acme/${field[$i]}}
echo ${formfield[$i]}
sed -i "s/test/test\n ${formfield[$i]}/" $targetForm
done
命令行说:
$foo_en = new Utils_Form_Element_Textarea('foo_en', array('langblock'=>'en', 'isWysiwyg' => true)); $this->addElement($foo_en); $this->addElement('textarea','foo_fr', array( 'label'=>__('foo'), 'langblock'=>'fr', 'isWysiwyg' => true, 'altLangElem' => $foo_en));
sed: -e expression #1, char 120: unterminated `s' command
$bar_en = new Utils_Form_Element_Textarea('bar_en', array('langblock'=>'en', 'isWysiwyg' => true)); $this->addElement($bar_en); $this->addElement('textarea','bar_fr', array( 'label'=>__('bar'), 'langblock'=>'fr', 'isWysiwyg' => true, 'altLangElem' => $bar_en));
sed: -e expression #1, char 120: unterminated `s' command
也许特殊字符有问题,但我不知道如何解决。