Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an sh script:

#!/bin/bash
fullpath="$1"
filename="${fullpath##*/}"
dir="${fullpath:0:${#fullpath} - ${#filename}}" 
base="${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"
  fi
fi

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: ./convert.sh: ${fullpath:0...}: Bad substitution.

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

PS sorry for my bad english :(

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
add comment

2 Answers

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
add comment

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

#!/bin/bash
fullpath="$1"
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"
  fi
fi
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
add comment

Your Answer

 
discard

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.