#!/bin/bash
# I get the newest file in Directory
latest_file=$(ls -t | head -n 1)
getAlldoublicate()
# getting Token syntax error here getAlldoublicate() '{
{
Alldoublicate=$(tr -s ',' ' ' <latest_file | awk '{print $2" "$3" "$4}' | uniq -d)
# here I try to find dublicate rows in csv
}
if [[ -s latest_file]] ; then
# here I check if file is emty
getAlldoublicate
else
cat "$latest_file" | mailx -s "$latest_file is empty" bla..`@bla
fi
答案 0 :(得分:1)
我想这是你的代码。
#!/bin/bash
# I get the newest file in Directory
latest_file=$(ls -t | head -n 1)
# getting Token syntax error here
getAlldoublicate()
{
# here I try to find dublicate rows in csv
Alldoublicate=$(tr -s ',' ' ' < $1 | awk '{print $2" "$3" "$4}' | uniq -d)
}
if [[ -s $latest_file ]]; then
# here I check if file is emty
getAlldoublicate $latest_file
else
cat $latest_file | mailx -s "$latest_file is empty" bla.. @bla
fi
你需要注意三点:
function
必须在使用前先定义。latest_file
时,您可以将getAlldoublicate
作为参数传递。然后你可以在函数中$1
使用它。 ($0
代表被称为自身的函数。)