0

Right now i a have a working script to pass 2 arguments to a shell script. The script basically takes a ticket# and svn URL as arguments on command line and gives an output of all the revisions that have been changed associated with that ticket# (in svn comments).

#!/bin/sh

jira_ticket=$1
src_url=$2


revs=(`svn log $2 --stop-on-copy | grep -B 2 $1 | grep "^r" | cut -d"r" -f2 | cut -d" " -f1| sort`)

for revisions in ${!revs[*]}
    do
    printf "%s %s\n" ${revs[$revisions]}
done

Output:

4738
4739
4743
4744
4745

I need some help to pass an array of arguments - meaning more than one ticket# and give the output of revisions associated with those ticket numbers that get passed as args to the script.

iaav
  • 484
  • 2
  • 9
  • 26

1 Answers1

0

I don't think POSIX shell has arrays, so be plain and use #!/bin/bash

I would put the url as the first arg, and all the reset are tickets

#!/bin/bash
revs=()
src_url=$1
svn_log=$(svn log "$src_url" --stop-on-copy)
shift
for jira_ticket in "$@"; do   
    revs+=( $(grep -B 2 "$jira_ticket" <<< "$svn_log" | grep "^r" | cut -d"r" -f2 | cut -d" " -f1) )
done
for revisions in $( printf "%s\n" "${!revs[@]}" | sort )
    do
    printf "%s %s\n" ${revs[$revisions]}
done
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • 1/ What is $1 and $2 here ? 2/ What if there is 3rd arg to be passed like $target_url ? – iaav May 14 '13 at 14:08
  • @iaav, I updated by answer a bit to correct my errors from pasting your code. It should be more clear. Also, it only calls `svn log` once, so optimized a bit. – glenn jackman May 14 '13 at 16:35
  • I suspect I have not answered your real question: please post the output of `svn log` – glenn jackman May 14 '13 at 16:41
  • is this the usage? `./script.sh $src_url ticket-1 ticket-2 ticket-3 ?` – iaav May 14 '13 at 17:28
  • yes exactly. Once the src_url is assigned and the first parameter is `shift`ed, all the remaining parameters (`"$@"`) are tickets – glenn jackman May 14 '13 at 21:25
  • I gave this at command line: `./script.sh $src_url $target_url ticket-1 ticket-2 ticket-3` and it ignore $target_url and took the tickets as $@. I thought it would take all the parameters after $src_url. – iaav May 16 '13 at 23:45