Computing.Net > Forums > Unix > How to remove '$' from a $ variable

How to remove '$' from a $ variable

Reply to Message Icon

Original Message
Name: n1988
Date: October 12, 2007 at 10:42:30 Pacific
Subject: How to remove '$' from a $ variable
OS: Unix
CPU/Ram: N/A
Model/Manufacturer: N/A
Comment:

I like to know how to remove '$' from a $ variable.

I create a script, a.sh as below:

#!/usr/bin/ksh
a=`echo $1 | cut -d"\$" -f1`
b=`echo $1 | cut -d"\$" -f2`
echo $a$b

However, this script does not work as I expect

For example when I run the script as below:

a.sh abc$def.

The script displays 'abcabc' instead
of 'abcdef'


Report Offensive Message For Removal


Response Number 1
Name: cristian23
Date: October 17, 2007 at 08:34:12 Pacific
Reply: (edit)

Parameter $1 has value the "abc" and not "abc$def"; at the command line the $def substring is interpreted as a variable.

Calling
a.sh 'abc$def'
or
a.sh abc\$def
should output "abcdef".


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: How to remove '$' from a $ variable

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge