1
我收到一个错误,指出:“第32行(最后一行):语法错误:意外的文件结尾”。我找不到错误的来源。awk in Shell脚本错误:意外的文件结尾
的脚本首先输入:输入文件名
为脚本第二个输入:员工姓名
输入文件的第二栏:员工姓名
输入文件的第五栏:工资
输入文件的第六列:接合
贝洛日期w是我的脚本:
# Check whether or not the command has two arguments
if [ $# -ne 2 ]; then
echo "You must enter 2 arguments!\n"
echo "Application is now exiting..."
exit
fi
# Check whether or not the employee name supplied by the user is available in the input file
awk -v employee_name=$2 -v is_employee_available=0 -v year=0 -v new_salary=0
'BEGIN{FS="|"}
{
if(employee_name == $2) {
is_employee_available=1;
year=strtonum(substr($6,8,11));
if(year==1990)
new_salary=$5+2000;
else if(year==1991)
new_salary=$5+1500;
else if(year==1992)
new_salary=$5+1000;
else if(year>1992)
new_salary=$5+500;
else
print "Invalid year of joining!";
}
}
END
{
if(is_employee_available==0)
print "The provided employee does not exist!";
}' $1
谢谢。
不一定相关,但'$ 1'和'$ 2'应在shell脚本部分中引用。另外,我认为引用的脚本部分应该与'awk'在同一行开始。 – Chris
@Chris是的,谢谢你给我最好的建议。 –