我现在有脚本,但它总是提示这是错误。
stderr=/bin/sh: module: line 1: syntax error: unexpected end of file /bin/sh: error importing function definition for
模块'`
#!/bin/sh
#
# pgp.sh
# Script to take PGP Command Line 6.5.8 (Freeware) output from PGPPackageService
# or PGPUnpackageService and execute the appropriate GnuPG commands
#
if [ "$9" = "-se" ]
then MODE="encrypt_and_sign"
fi
if [ "$9" = "-e" ]
then MODE="encrypt_only"
fi
if [ "$8" = "-o" ]
then MODE="decrypt"
fi
#
case "$MODE" in
"encrypt_and_sign")
#
# Logic for encrypt and sign
#
if [ "$6" = "+armor=on" ];
then
OPTIONS='--armor '$OPTIONS
fi
if [ "$7" = "+textmode=on" ];
then
OPTIONS='--textmode '$OPTIONS
fi
PASS=${15}
OUTFILE=${17}
USER=${13}
REMOTE=${11}
INFILE=${10}
#Original script from Bryce
#echo "$PASS" | "gpg $OPTIONS --no-tty --output $OUTFILE --passphrase-fd 0 -u $USER -r $REMOTE --sign --encrypt $INFILE"
#script from Tyn, removed --passphrase-fd 0 and echo and double quotes
#03252015: Tyn: Added --trust-model always for newly imported keys to be usable
/usr/bin/gpg --trust-model always $OPTIONS --no-tty --output $OUTFILE -u $USER -r $REMOTE --sign --encrypt $INFILE
;;
"encrypt_only")
#
# Logic for encrypt
#
if [ "$6" = "+armor=on" ];
then
OPTIONS='--armor '$OPTIONS
fi
if [ "$7" = "+textmode=on" ];
then
OPTIONS='--textmode '$OPTIONS
fi
OUTFILE=${13}
REMOTE=${11}
INFILE=${10}
#original script from Bryce
#echo "$PASS" | "gpg $OPTIONS --no-tty --output $OUTFILE --passphrase-fd 0 -r $REMOTE --encrypt $INFILE"
#script from Tyn, removed --passphrase-fd 0 and echo and double quotes
#03252015: Tyn: Added --trust-model always for newly imported keys to be usable
/usr/bin/gpg --trust-model always $OPTIONS --no-tty --output $OUTFILE -r $REMOTE --encrypt $INFILE
;;
"decrypt")
#
# Logic for decrypt
#
PASS=${7}
OUTFILE=${9}
INFILE=${5}
#Original script from Bryce
#echo "$PASS" | "gpg --no-tty --output $OUTFILE --passphrase-fd 0 --decrypt $INFILE"
#script from Tyn, removed --passphrase-fd 0 and echo and double quotes
#03252015: Tyn: Added --trust-model always for newly imported keys to be usable
/usr/bin/gpg --trust-model always --no-tty --output $OUTFILE --decrypt $INFILE
;;
esac
答案1
看起来您的环境中有一个损坏的导出函数,如下所示(该函数缺少分号和右大括号):
$ env "BASH_FUNC_foo%%"="() { echo foo" bash -c "echo blah"
bash: foo: line 1: syntax error: unexpected end of file
bash: error importing function definition for `foo'
blah
Bash 通过环境导出函数并自动从那里读取它们,当然如果它们有语法错误就会抱怨。即使开始时它也会这样做sh
。这意味着您在运行任何脚本时都会遇到相同的错误,例如这个简单的错误:
#!/bin/sh
echo hello
您可以使用类似的内容检查环境中的内容env | grep module
(前缀BASH_FUNC_
和后缀%%
可能不同)。然后,您需要找出该环境变量的设置位置。不过,在 Bash 脚本中设置它相当困难,因为%
不是 shell 变量名称中的有效字符。