how to get rid of ' from variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to get rid of ' from variable?
# 1  
Old 12-27-2009
how to get rid of ' from variable?

hi,

I want to get rid of ' from my variable value in ksh, and I also want to read the value on the right hand side of = into a variable

thanks
# 2  
Old 12-27-2009
Question is not very clear but here is what I think you are after:
Code:
$ AJF=\'fred\'; export AJF
$ env | grep AJF
AJF='fred'

We have a variable whose value includes the ' character.

To extract the value from the above do:
Code:
$ echo $AJF | awk -F"'" '{ print $2 }'
fred
$

To put the extracted value into a new variable do:
Code:
$ BHG=`echo $AJF | awk -F"'" '{ print $2 }'`
echo $BHG
fred
$

# 3  
Old 12-27-2009
thanks.

The second part I mean I have

var=test

and I want to extract the value test, how can I do this?

thanks
# 4  
Old 12-27-2009
This should work too if you have one or more quotes in the variable:

Code:
var=$(echo $test | awk '{gsub("\047","")}1')

# 5  
Old 12-27-2009
Code:
$ var="'test'"
$ echo $var
'test'

How about:
Code:
$ eval var=$var
$ echo $var
test

# 6  
Old 12-27-2009
thanks all for the answers,

i was just hoping to find out if there is a way using built in ksh functionality

thanks
# 7  
Old 12-27-2009
Quote:
Originally Posted by JamesByars
thanks all for the answers,

i was just hoping to find out if there is a way using built in ksh functionality
A built in ksh functionality for what? To remove the sigle quote character from a variable? To extract the characters after the = sign?
What version of the Korn Shell are you using: ksh88, ksh93, pdksh?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting rid of ^M

I have a text file with hundreds of 32-character hash codes in it, each terminated with a linefeed (/l, or ^M). 185ead08e45a5cbb51e9f7b0b384aaa2 57643e1a17252a9fc746d49c3da04168 60cba11d09221d52aaabb5db30f408a2 2b75ee6e5c2efc31b4ee9a190d09a4df ...... etc. I want to create a file for each... (6 Replies)
Discussion started by: teledon
6 Replies

2. Linux

How to get rid of ^m

Hi all, I am new to unix....pls help me with this. I have a binary file generating output by passing arguments in bash.when i open the output file in VI i can see that ^m is included in between most of lines,as a result when i pass this file to my java application it dosent parse the data... (3 Replies)
Discussion started by: asheshrocky
3 Replies

3. UNIX for Dummies Questions & Answers

How to get rid of ^[[D

Hi All, Im selecting a large record from a table and putting it in a file in the unix box. The file has a hidden character "^[[D " present in it. Can any one help me in getting rid of the character Thanks in advance, (4 Replies)
Discussion started by: madhan@29
4 Replies

4. Shell Programming and Scripting

how to get rid of ^M in the file

Hi I have a file wich contains ^M characters, looks like these are from DOS, Is there a way to get rid of them? Thanks -A (3 Replies)
Discussion started by: aoussenko
3 Replies

5. UNIX for Dummies Questions & Answers

how to get rid of ==>

ok the assignment question: That English paper you were writing on the works of Lewis Carroll is due in a few hours and you have forgeotten the name of the text file in which you has written a number of quotations to use in your paper. Luckily, you know that the file is somewhere in your... (1 Reply)
Discussion started by: mek86
1 Replies

6. Solaris

how to get rid of ok prompt

Hi: My ultra 10 booted up to the ok prompt. does anyone how to get to the # prompt in normal mode? Alan (1 Reply)
Discussion started by: alanj9000
1 Replies

7. Debian

Getting rid of grub

ok so i have two HDs on my PC, on the 1st one (master) i have w2k running, i decided to install debian on the second (slave). During the install, i was asked if i wanted to install grub, i said yes. Now debian starts just fine. Windows on the hand now takes forever to load (ie like two minutes... (4 Replies)
Discussion started by: jad
4 Replies

8. Solaris

getting rid of ^H

Hello everybody I have a very annoying problem on my Solaris (Unix in general) servers. When I open a shell and press the backspace button, it results in a ^H character being printed on screen. I can resolve it by typing stty erase <backspace>, but does anyone know how I can prevent the... (3 Replies)
Discussion started by: soliberus
3 Replies

9. IP Networking

How to get rid of DCHP ?

Hi all:- I am using Sun8 Intel PC in a network and have IP allocated by DHCP. Now I got a static IP and want to configure my PC for this new IP and disable DHCP. How can I do that ? Thanks in advance (3 Replies)
Discussion started by: s_aamir
3 Replies

10. UNIX for Advanced & Expert Users

How to get rid of DCHP

Hi all:- I am using Sun8 Intel PC in a network and have IP allocated by DHCP. Now I got a static IP and want to configure my PC for this new IP and disable DHCP. How can I do that ? Thanks in advance (6 Replies)
Discussion started by: s_aamir
6 Replies
Login or Register to Ask a Question