我在第22行遇到错误:[!:找不到命令
我的脚本询问姓名,电话号码和出生日期,然后将这些详细信息修改为名为“birthday.csv”的逗号分隔值文件。
然后按出生日期对“birthday.csv”进行排序。然后显示新排序的文件并计算其年龄。
有人可以查看我的脚本,看看为什么会出现这种情况。
#!/bin/bash
a=0
while [ $a -lt 2 ];
do
echo Please enter a first name
read firstName
echo Please enter last name
read lastName
echo Please enter phone number
read phoneNumber
echo Please enter date of birth - format dd/mm/yyyy
read dob
echo "$firstName,$lastName,$phoneNumber,$dob" >> userBirthdays.csv
echo If you would like to add another person press 1 or enter 2 to proceed
read a
done
INPUT=./userBirthdays.csv
OLDIFS=$IFS
IFS=","
[! -f INPUT] & while read Name Surname Telephone DOB
do
birthMonth=${DOB:0:2}
birthDay=#10${DOB:3:2}
birthYear=${DOB:6:4}
currentDate=`date +%d/%m/%Y`
currentMonth=${currenDate:0:2}
currentDay=#10${currentDate:3:2}
currentYear=${currentDate:6:4}
if [[ "$currentMonth" -lt "$birthMonth" ]] || [[ "$currentMonth" -eq "$birthMonth" && "$((#10$currentDay))" -lt "$((#10$birthDay))" ]]
then
let Age=currentYear-birthYear-1
else
let Age=currentYear-birthYear
fi
echo "Name : $Name"
echo "Surname : $Surname"
echo "Telephone : $Telephone"
echo "DOB : $DOB"
echo "Age : $Age"
echo "##########################################"
done < $INPUT
IFS=$OLDIFS
echo $DATE
exit 0;
提前谢谢
答案 0 :(得分:3)
[ ! -f $INPUT ] && while read ....
#^-^--------^-^---^------------
请注意,你几乎肯定想要两个'&amp;' chars,就像我的纠正一样。
感谢@GordonDavisson为另一个'$'; - )
IHTH
答案 1 :(得分:1)
使用空格分隔[
和!
,因此[
将是一个命令,而!
将是它的第一个参数,就像你想要的那样。 / p>
(不确定没有其他问题)。