0

Below is a command I use to merge multiple .wav files into a single file named output.wav :

ffmpeg -f concat -safe 0 -i <( for f in *.wav; do echo "file '$(pwd)/$f'"; done ) output.wav

This works as expected but when I add it to a script named merge-into-one.sh with permission :

-rwxrwxrwx  1 ddsasd  staff        93 26 Dec 11:50 merge-into-one.sh

and then execute using ./merge-into-one.sh I receive error :

./merge-into-one.sh
./merge-into-one.sh: line 1: syntax error near unexpected token `('
./merge-into-one.sh: line 1: `ffmpeg -f concat -safe 0 -i <( for f in *.wav; do echo "file '$(pwd)/$f'"; done ) output.wav'

Have I created the .sh executable correctly ?

blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • What's your shebang? `<(...)` is extended syntax that `#!/bin/sh` doesn't support. – Charles Duffy Jan 03 '20 at 21:47
  • Use `#!/usr/bin/env bash` to ensure that bash-only syntax is available. – Charles Duffy Jan 03 '20 at 21:48
  • ...on a related note, naming bash scripts with `.sh` extensions is not good form. Better to not use an extension at all and encourage users to use the shebang instead of assuming they can run `sh foo.sh` (when your script may actually require bash, zsh, or another non-PONIX shell). And UNIX commands don't generally have extensions in general; you don't run `ls.elf` – Charles Duffy Jan 03 '20 at 21:49
  • try to mentioned sheband #!/bin/bash – mahendra rathod Jan 03 '20 at 21:49
  • @mahendrarathod, on MacOS `#!/bin/bash` is a bad choice since it uses an ancient GPLv2 release even if the user installed a modern bash release with MacPorts/Homebrew/Nix/etc. The `#!/usr/bin/env bash` shebang suggested above uses the PATH to look up the interpreter to use. – Charles Duffy Jan 03 '20 at 21:50
  • It's not a bad choice if you don't actually need the newer features of `bash` 4. (Yes, I'm using the term "newer" loosely :) – chepner Jan 03 '20 at 21:50
  • @chepner, ...granted, we're in reasonable-minds-can-differ territory, but insofar as Apple isn't exactly backporting noncritical bugfixes to their 3.2.x build, using it strikes me as a bad idea regardless. And even bash 4 is no longer the active upstream major release; 3 is downright decrepit these days. – Charles Duffy Jan 03 '20 at 21:51
  • @CharlesDuffy thank you for valuable information. – mahendra rathod Jan 03 '20 at 21:55

0 Answers0