0

OS: Raspbian

I'm currently working on a bash script that will merge all .AVI videos in the current directory, to one .AVI file. I've found the following to work perfectly for me, when run directly in the terminal:

ffmpeg -f concat -safe 0 -i <(find . -name '*.avi' -printf "file '$PWD/%p'\n") -c copy "$(date -d '-1 day' +'%F')".avi

This works perfectly, and I find a new .AVI file listed in the current directory (with a date name from yesterday).

Now, when I add this same command to my script (merge.sh), I get the following output:

/home/pi/Documents/MotionScripts/merge.sh: 11: 
/home/pi/Documents/MotionScripts/merge.sh: Syntax error: "(" unexpected

This is beyond frustrating. And yes, ffmpeg command from earlier is on line 11. The script navigates to the correct directory where the multiple .avi files are stored.

Here is the entire script:

#!/bin/bash

#This script combines multiple AVI files within the current directory, into one long video

cd /media/myBook/Security/yesterday

sudo mv * /home/pi/Videos/tempconversion

cd /home/pi/Videos/tempconversion

ffmpeg -f concat -safe 0 -i <(find . -name '*.avi' -printf "file '$PWD/%p'\n") -c copy "$(date -d '-1 day' +'%F')".avi

sudo mv "$(date -d '-1 day' +'%F')".avi /media/myBook/Security/yesterday

sudo rm -f *

Why am I getting the syntax error only when the same command is being issued within an executable script?

RESOLVED! Shouldn't have used 'sh' to run the script. Make sure the script is executable (sudo chmod +x merge.sh) and run by entering the full path.

bmck2006
  • 122
  • 8
  • 2
    Your syntax seems ok to me, `bash` should accept it. Maybe you are using a different shell when you run it interactively in the terminal than the one used for the script. Try something like `readlink /proc/$$/exe` for both scenarios, it should give you the path to the shell executable being used. – redneb Dec 10 '17 at 03:47
  • Yes, you are correct. I was using 'sh' to run the script instead of just entering the full path. All is working now! – bmck2006 Dec 10 '17 at 04:11
  • This is, by the way, number 2 on the checklist of the [Bash tag wiki](https://stackoverflow.com/tags/bash/info). – Benjamin W. Dec 10 '17 at 04:28

0 Answers0