X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Message-ID: Date: Tue, 14 Oct 2008 20:01:44 -0400 From: "Mark J. Reed" To: cygwin AT cygwin DOT com Subject: Re: cygwin shell scripting - how to pass values from command line to ssh remote command In-Reply-To: <1f97de60810141159u193de792pe496d7a044265738@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1f97de60810141159u193de792pe496d7a044265738 AT mail DOT gmail DOT com> X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On Tue, Oct 14, 2008 at 2:59 PM, Z W wrote: > Question: > How can I pass arguments on command line with test.sh such that > variables MAX_MS, OFFSET_MS, THREADS, RAMP and LOOPS > could receive the argument parameters as opposed to hardcoding the numbers ? This isn't really a cygwin question; there are lots of shellscripting tutorials on the web, which I recommend you look for. Meanwhile, however, try this: #!/bin/bash function usage { echo >&2 "Usage: $0 [-h|-l loops|-m max_ms|-o offset_ms|-r ramp|-t threads]" exit $1 } # default values loops=2 max_ms=100 offset_ms=89900 ramp=1 threads=4 while getopts 'hl:m:o:r:t:' opt; do echo opt=$opt case "$opt" in h) usage 0;; l) loops="$OPTARG";; m) max_ms="$OPTARG";; o) offset_ms="$OPTARG";; r) ramp="$OPTARG";; t) threads="$OPTARG";; ?) usage 1;; esac done shift $(( OPTIND - 1 )) if (( $# )); then usage 1 fi ssh localhost 'cd /cygdrive/c/apps/bin && LOOPS="'"$loops"'" MAX_MS="'"$max_ms"'" OFFSET_MS="'"$offset_ms"'" RAMP="'"$ramp"'" THREADS="'"$threads"'" nohup ./start.sh & ps -efW | grep java' That ssh command should be all on one line. Careful with the sequences of quotation marks. The idea is to build a command string that includes literal quotation marks intermixed with the quoted expansion of local variables. Also note that if all you're looking to getting out of that ps |grep java line is the PID, you can just use $!. -- Mark J. Reed -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/