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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to remove '$' from a $ variable

Reply to Message Icon

Name: n1988
Date: October 12, 2007 at 10:42:30 Pacific
OS: Unix
CPU/Ram: N/A
Product: 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'



Sponsored Link
Ads by Google

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

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".


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: How to remove '$' from a $ variable

How to Remove LILO from Windows NT boot www.computing.net/answers/unix/how-to-remove-lilo-from-windows-nt-boot-/2230.html

How to remove files www.computing.net/answers/unix/how-to-remove-files/7421.html

how to test ports www.computing.net/answers/unix/how-to-test-ports/5236.html