1
#!/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
4
  • 3
    Could you please add your actual code without annotations? Commented Jun 7, 2017 at 3:53
  • 4
    Use shellcheck.net to diagnose syntax errors in your shell code. Commented Jun 7, 2017 at 3:55
  • Could you please format your code and add the error phrases? Commented Jun 7, 2017 at 4:33
  • 1
    If your actual code is getAlldoublicate() '{, then the problem is the stray single quote. But you haven't posted your code, so it's hard to say. Commented Jun 7, 2017 at 13:30

1 Answer 1

1

I guess this is your code.

#!/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

Three points you need to pay attention:

  1. function must be defined first before being use.
  2. You can pass the latest_file as an argument when calling getAlldoublicate. Then you could use it by $1 in the function. ($0 stands for the function being called itself).
  3. It would be better if you read the How to Format Tutorials before asking questions.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.