1

I'm using FPM to create Debian packages, and I've run into a little problem. My bash script takes 5 arguments.

TARGET=$1
VERSION=$2
DESCRIPTION=$3
DEPENDENCIES=$4
REVISION=$5

The troublesome one is $4, where I pass it the following string

-d "apt-transport-https > 0.8.16~exp12ubuntu10.15" -d "mongodb > 1:2.0.4-1ubuntu2" -d "ntp > 1:4.2.6.p3+dfsg-1ubuntu3.1"

The double quotes are escaped in my string, so when I echo $DEPENDENCIES, the quotes show up correctly.

FPM uses the -d flag can be used multiple times, and I need to be able to pass a list of parameters from my script to fpm.

I would like to do something like:

fpm ...blah blah details... $DEPENDENCIES path

$DEPENDENCIES should pass the multiple flags to fpm, but it only seems to recognize the first one. If I write the arguments out manually, it works fine, but trying to use a string to pass the parameters doesn't work.

I'm not sure what's up. Help?

C Fairweather
  • 696
  • 4
  • 20

1 Answers1

9

This will be helpful reading: http://mywiki.wooledge.org/BashFAQ/050

If I were you, I would rearrange your parameters

#!/bin/bash
TARGET=$1
VERSION=$2
DESCRIPTION=$3
REVISION=$4
shift 4
DEPENDENCIES=( "$@" )

Dependencies is "all the rest" of the arguments, properly separated. You will invoke your script like this

./script tgt ver "this is the description" rev-1.1.1 -d "apt-transport-https > 0.8.16~exp12ubuntu10.15" -d "mongodb > 1:2.0.4-1ubuntu2" -d "ntp > 1:4.2.6.p3+dfsg-1ubuntu3.1"

In your script, the DEPENDENCIES array will contain these elements

DEPENDENCIES[0]=-d 
DEPENDENCIES[1]="apt-transport-https > 0.8.16~exp12ubuntu10.15" 
DEPENDENCIES[2]=-d 
DEPENDENCIES[3]="mongodb > 1:2.0.4-1ubuntu2" 
DEPENDENCIES[4]=-d 
DEPENDENCIES[5]="ntp > 1:4.2.6.p3+dfsg-1ubuntu3.1"

In your script, call fpm like:

fpm ...blah blah details... "${DEPENDENCIES[@]}" path
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • Thanks dude. +1 for link to reading. I can get around most things, but this was beyond my grasp. Did `shift 4>/dev/null` just for quiet. – C Fairweather Oct 16 '13 at 17:15