User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,432 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,619 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 3400 | Replies: 4
Reply
Join Date: Jun 2007
Posts: 3
Reputation: TheDonDon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
TheDonDon TheDonDon is offline Offline
Newbie Poster

Question KSH Passing parameters that start with $

  #1  
Jun 14th, 2007
I'm completely new to this and have fallen at the first hurdle.

I'm only playing so its not urgent.

Here is my little bit of code:

#!/bin/ksh
print Content-type: text/html
print
print '<pre style=font-family:Fixedsys>'
gtacl -c 'files $usvol1.ssdxl' |{
while read line ;do
print "${line%%=*}"
done
}
print '</pre>'

Don't worry too much about the gtacl command as that's machine specific but suffice to say the the files $usvol1.ssdxl has to be passed as is hence the single quotes (I think!).

What I'd like to do is change the code such that the $usvol1.ssdxl gets passed in as a parameter on the command line so it has to become:

gtacl -c "files $1"

The $1 gets expanded to the value of the parameter but then because the expanded value starts with a $ KSH tries to interpret as something other than a text string.

I've tried hard, but how does one get around this?

Cheers

Don
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2007
Posts: 52
Reputation: radoulov is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
radoulov's Avatar
radoulov radoulov is offline Offline
Junior Poster in Training

Re: KSH Passing parameters that start with $

  #2  
Jun 14th, 2007
Works for me, don't you want a command like this?

$ f='$usvol1.ssdxl'
$ echo "gtacl -c 'files $f'"
gtacl -c 'files $usvol1.ssdxl'
Reply With Quote  
Join Date: Jun 2007
Posts: 3
Reputation: TheDonDon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
TheDonDon TheDonDon is offline Offline
Newbie Poster

Re: KSH Passing parameters that start with $

  #3  
Jun 15th, 2007
Hi radoulov,

Thanks but, still struggling I'm afraid.
Here is new test script (my file is called cgic)

#!/bin/ksh
echo "1 is 'files $1'"
a=$1
echo "a is 'files $a'"
b="$1"
echo "b is 'files $b'"
c='$1'
echo "c is 'files $c'"

From command line invoke thus:
./cgic This.is.a.test.string

Results:
1 is 'files This.is.a.test.string'
a is 'files This.is.a.test.string'
b is 'files This.is.a.test.string'
c is 'files $1'

From command line invoke thus:
./cgic $usvol1.ssdxl

Results:
1 is 'files .ssdxl'
a is 'files .ssdxl'
b is 'files .ssdxl'
c is 'files $1'
Last edited by TheDonDon : Jun 15th, 2007 at 4:15 am.
Reply With Quote  
Join Date: Feb 2007
Posts: 52
Reputation: radoulov is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
radoulov's Avatar
radoulov radoulov is offline Offline
Junior Poster in Training

Re: KSH Passing parameters that start with $

  #4  
Jun 15th, 2007
You have to escape the $ sign:
$ cat script
#!/bin/ksh
echo "1 is 'files $1'"
a=$1
echo "a is 'files $a'"
b="$1"
echo "b is 'files $b'"
c='$1'
echo "c is 'files $c'"
$ ./script '$usvol1.ssdxl'
1 is 'files $usvol1.ssdxl'
a is 'files $usvol1.ssdxl'
b is 'files $usvol1.ssdxl'
c is 'files $1'
$ ./script \$usvol1.ssdxl
1 is 'files $usvol1.ssdxl'
a is 'files $usvol1.ssdxl'
b is 'files $usvol1.ssdxl'
c is 'files $1'
Reply With Quote  
Join Date: Jun 2007
Posts: 3
Reputation: TheDonDon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
TheDonDon TheDonDon is offline Offline
Newbie Poster

Re: KSH Passing parameters that start with $

  #5  
Jun 15th, 2007
Thanks, may have a couple of other little queries re this.

Cheers
Don
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:28 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC