Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an sh script:

dir="${fullpath:0:${#fullpath} - ${#filename}}" 
ext="${filename:${#base} + 1}"   
if [ -f $fullpath ]; then
  if [ $ext != "mp4" ]; then
      ffmpeg -threads 4 -i $fullpath -y -vcodec libx264 -g 100 -bt 100k mp4 -vpre fast -acodec libfaac -ab 128k "$dir$base.mp4"
      mv -f "$dir$base.mp4" "/data/www/rfpl/htdocs/videotapes/$base.mp4"

So, I wrote it for Linux, now I need to run it under FreeBSD, but I don't know anything about FreeBSD. There is an error:

./ ${fullpath:0...}: Bad substitution.

I think that there is no bash, how can I make it to work?

share|improve this question
Your script is running bash. Is it an old version? I'm wondering also if maybe you changed your script to run /bin/sh and forgot to indicate that in the question? – Phil Hollenback May 21 '11 at 19:24
up vote 2 down vote accepted

If you don't have bash installed already, then the FreeBSD preferred way is to use the ports:

cd /usr/ports/shells/bash
make install clean

If you don't have the ports tree installed, you can install it by running:

portsnap fetch extract

Doing either of these things will need root privs.

Note also, that typically bash is installed in /usr/local/bin/bash So you'll want to edit the first line of your script. In fact check that bash isn't already installed, before trying the above.

share|improve this answer
This is a good answer, but the OPs script says it is already running bash. So I wonder why he can't use standard bashisms? Maybe he's running a really old bash? Maybe the question is just missing some info. – Phil Hollenback May 21 '11 at 19:23

I don't have access to a freebsd box, but try this:

filename=$(basename $fullpath)
dir=$(dirname $fullpath)
ext=$(echo $filename | awk -F. '{ print $NF }')
base=$(echo $filename | sed "s/.${ext}//")
if [ -f $fullpath ]; then
  if [ $ext != "mp4" ]; then
    ffmpeg -threads 4 -i $fullpath -y -vcodec libx264 -g 100 -bt 100k mp4 -vpre fast -acodec libfaac -ab 128k "$dir/$base.mp4"
    mv -f "$dir/$base.mp4" "/data/www/rfpl/htdocs/videotapes/$base.mp4"
share|improve this answer
I was just going to post something very similar - I checked the bsd man pages and dirname/basename are available. – Iain May 21 '11 at 16:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.