1

I am using OS X Yosemite. I want to make a simple bash script that allows me to transcode a video. Everything works well as long as a file is not located in a directory which has spaces.

Here is my script:

#!/bin/sh

ffmpeg -i “$1” -c:v ffv1 -level 3 -g 1 -c:a copy “$1.mkv” 

Initially, I did not have the double quotes around the variable, but I read some stack overflows that used this as a solution. I'd rather not have to alter the path or add slashes etc. I want to just run:

 ./script.sh filename.mov 

Here's the error I get:

Kierans-iMac:~ bla$ ./firstscript.command "/Users/bla/Desktop/untitled\ folder\ 2/v210.mov.mkv" 
ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.2_1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libfreetype --enable-libfaac --enable-libass --enable-ffplay --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.2_1/include/openjpeg-1.5 ' --enable-nonfree --enable-vda
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
“/Users/bla/Desktop/untitled\: No such file or directory
3
  • your actual cmd is ./firstscript.command "/Users/bla/Desktop/untitled\ folder\ 2/v210.mov.mkv" . A path is a path, either you cd to the dir and execute from there, or you have to pass the path (full or relative) in your command. As you have already dbl-quoted your path try removing the 2 '\' chars escaping the spaces. OR eliminate a whole class of error from using a unix derived systems and don't use spaces in dir or filenames ;-! Good luck. Commented Aug 19, 2015 at 18:05
  • Are you using proper ASCII double quotes, or the curly quotes shown in this question? Commented Aug 19, 2015 at 18:07
  • Thanks for replying! I just used script.sh as a generic example. I removed the double quotes from the path, so now it's ./firstscript.command /Users/bla/Desktop/untitled\ folder\ 2/v210.mov.mkv but it's the same error. Commented Aug 19, 2015 at 18:08

1 Answer 1

2

You are quoting the spaces twice:

./firstscript.command "/Users/bla/Desktop/untitled\ folder\ 2/v210.mov.mkv"

should just be

./firstscript.command "/Users/bla/Desktop/untitled folder 2/v210.mov.mkv"

A quoted string "foo" is equivalent to \f\o\o; every character is escaped. The backslashes in your original are treated as literal backslashes.

Inside the script, you still need to quote the parameter expansion:

ffmpeg -i "$1" -c:v ffv1 -level 3 -g 1 -c:a copy "$1.mkv"

Note that you have to use regular ASCII quotes ("), not the "smart" quotes () implied by the error message in your link.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I did indeed have those smart quotes in my script. When I enabled the ascii quotes, the script worked! Actually, i didn't even need to put the quotes around the command in terminal. Hopefully I won't have to, as it seemed to work just fine with no quotes?
Right; "foo bar" and foo\ bar are identical strings after the shell performs quote removal

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.