The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using getopts TurboArkhan Shell Programming and Scripting 3 06-22-2009 04:31 PM
Help in getopts chella Shell Programming and Scripting 4 11-02-2007 01:09 AM
getopts help GrepMe Shell Programming and Scripting 3 06-20-2007 11:47 AM
help in getopts problems Shell Programming and Scripting 1 05-04-2006 11:07 PM
getopts yerra Shell Programming and Scripting 5 03-26-2005 10:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-05-2002
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
getopts

I have a script that facillitates NDM (Connect::\Direct) transfer to remote hosts. This script uses getopts to parse through the parameters passed to it and to set appropriate variables based upon what was passed in.

Kickoff="mv $PATH/$FILE1 $PATH/$FILE2"

ndm_shell.ksh -p $Node -s $Source -d $Destination -k $Kickoff

My issue arrises with the Kickoff variable. When I pass this to my ndm_shell getopts sets the value of the host script variable to "mv "

My question: Is there a way to pass a single variable that resolves to multiple arguments to getopts so that my internal variable contains the entire string?

Last edited by google; 12-05-2002 at 05:48 PM..
  #2 (permalink)  
Old 12-05-2002
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Have you tried quotes?

ndm_shell.ksh -p $Node -s $Source -d $Destination -k "$Kickoff"

instead of
ndm_shell.ksh -p $Node -s $Source -d $Destination -k $Kickoff
  #3 (permalink)  
Old 12-05-2002
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
interesting behavior
if I pass the variable in quotes, -k"${KICKOFF}" then getopts will asign the variable inside of my case statement as follows:

while getopts p:n:s:d:lf:c:k:u:w:g:h:i: opt
do
case $opt in
k)
KICKOFF_PROG=$OPTARG
;;
esac
done

echo "Kickoff Program variable is set to $KICKOFF_PROG"

The echo above produces the following result:
Kickoff Program variable is set to ${KICKOFF}

but....
when I actually use the variable $KICKOFF_PROG it will resolve to the string I passed....interesting behavior.

Why doesnt the echo statement expand the variable?
  #4 (permalink)  
Old 12-05-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Quote:
Originally posted by google
Why doesnt the echo statement expand the variable?
The shell expanded variables once during the processing of the echo statement. It does not then loop to see if any new variable references were created.

If you want to expand a variable inside a variable, you need to use "eval echo".

As for your original question, you have multiple variables inside variables and it's not obvious to me when you want them expanded. One intrepretation would suggest that:
Kickoff="\"mv $PATH/$FILE1 $PATH/${FILE2}\""
might do the trick.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0