On Dec 21, Olli Ries wrote:
> On Sun, Dec 21, 2014 at 6:48 PM, Brian J. Rogers <[email protected]>
> wrote:
>
>> I can have written as the package, version, and operator, so I don't have
>> to try to parse or do any special checks to construct the line. So I want
>> to be able to read each line, pre-pend '-d' then wrap it in quotes, then
>> append a slash to prevent it from executing. There is a parameter after all
>> the dependencies so, so I don't have to leave the last slash off. The whole
>> command would look like this:
>>
>> fpm -s dir -t rpm -n {package} -v {version} -C /path/to/{package}/output \
>>   -p {package}-VERSION.fc21.ARCH.rpm \
>>   -d "{dependency-package} >= {version}" \
>>   -d "{dependency-package} >= {version}" \
>>   usr
>>
>>
> I am not quite sure I understand what your input is, but the below snippet
> will let you read lines into $REPLY and will append to a string $result.
>
> It probably doesn't entirely do what you need but should be close enough.
> If not, pls share your input and we'll have you taken care off.
>
> -snip-
>
> result=""
>
> while read; do
>   result="${result}\n-d \"${reply}\""
> done < $INFILE
>
> echo $result

For constructing a command line in bash, it might also help to use an
array, particularly if you want to execute the command right then.
That way, you don't have to worry about any quoting issues.  (Not that
you're likely to run into problems with standard package names and
versions, but just in case...)  For example:


declare -a deps

while read line
do
  deps+=(-d "$line")
done < $infile

fpm -s dir -t rpm -n "$package" -v "$version" \
  -C "/path/to/$package/output" \
  -p "$package-VERSION.fc21.ARCH.rpm" \
  "${deps[@]}" \
  usr


And yes, that last line even knows what to do if the file happens to be
empty, just like the "$@" magic.

- Eric

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to