0

I wrote a shell script that calls the ffmpeg tool but when I run it, it says No such file or directory yet it does!

Here is my script:

#!/bin/bash

MAIN_DIR="/media/sf_data/pipeline"

FFMPEG_DIR="/media/sf_data/livraison_transcripts/ffmpeg-git-20180208-64bit-static"

for file in MAIN_DIR/audio_mp3/*.mp3;
do
    cp -p file FFMPEG_DIR;
done

for file in FFMPEG_DIR/*.mp3;
do
    ./ffmpeg -i ${file%.mp3}.ogg
    sox $file -t raw --channels=1 --bits=16 --rate=16000 --encoding=signed-
integer --endian=little ${file%.ogg}.raw;
done

for file in FFMPEG_DIR/*.raw;
do
    cp -p file MAIN_DIR/pipeline/audio_raw/;
done

and here is the debug response:

cp: cannot stat ‘file’: No such file or directory
./essai.sh: line 14: ./ffmpeg: No such file or directory
sox FAIL formats: can't open input file `FFMPEG_DIR/*.mp3': No such file or 
directory
cp: cannot stat ‘file’: No such file or directory

FYI I'm running CentOS7 on VirtualBox

Thank you

Toto Tata
  • 43
  • 1
  • 5

2 Answers2

1

Here's a Minimal, Complete, and Verifiable example (MCVE), a version of your script that removes everything not required to show the problem:

#!/bin/bash
MAIN_DIR="/media/sf_data/pipeline"
echo MAIN_DIR

Expected output:

/media/sf_data/pipeline

Actual output:

MAIN_DIR

This is because bash requires a $ when expanding variables:

#!/bin/bash
MAIN_DIR="/media/sf_data/pipeline"
echo "$MAIN_DIR"

The quotes are not required to fix the issue, but prevent issues with whitespaces.

that other guy
  • 116,971
  • 11
  • 170
  • 194
0

Hi You need couple of correction in your shell script see below. To get the actual value assigned to a variable you need to add $ at the front of the variable in shell script.

for file in $"MAIN_DIR"/audio_mp3/*.mp3;
do
   cp -p "$file" "$FFMPEG_DIR";
done

for file in "$FFMPEG_DIR"/*.mp3;

./ffmpeg -i ${file%.mp3}.ogg
#provide full path like /usr/bin/ffmpeg

for file in "$FFMPEG_DIR"/*.raw;
do
   cp -p "$file" "$MAIN_DIR"/pipeline/audio_raw/;
done
Abhijit Pritam Dutta
  • 5,521
  • 2
  • 11
  • 17
  • You're missing a `do` and a `done` before and after the `ffmpeg` command. `${file%.mp3}.ogg` should also be quoted. – llogan Mar 15 '18 at 17:51