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?
# 8  
Old 12-27-2009
sorry,

I meant how to find out both. And how can I find out which version I am using of ksh?

thanks
# 9  
Old 12-27-2009
Assuming STRING is "ABC=DEF":
Code:
echo $STRING | awk -F"=" '{ print $1 }'

Will give you the text before the equals sign and:
Code:
echo $STRING | awk -F"=" '{ print $2 }'

or
Code:
echo $STRING | awk -F"=" '{ print $NF }'

will give you the value after the equals sign.
# 10  
Old 12-27-2009
Quote:
Originally Posted by JamesByars
sorry,
I meant how to find out both.
Both ...
With the AT&T ksh93 and mksh(MIRBSD KSH) you can remove the single quote(s) like this:

Code:
$ s="a'b'c'"
$ print -- $s           
a'b'c'
$ print -- ${s//\'}
abc

With ksh88 and pdksh I suppose you should use an external command (tr -d ?).

Regarding the second one:

Code:
$ s=a=b
$ print -- $s
a=b
$ print ${s%=*}
a
$ print ${s#*=} 
b

Quote:
And how can I find out which version I am using of ksh?
If the following command works, you have ksh93:

Code:
print ${.sh.version}

If the above command throws an error, you could run this one:

Code:
print $KSH_VERSION

It will return not an empty string if you have pdksh or mksh.

If neither of which works, you have ksh88. To get the exact version you'll need to set the editing mode (for example to vi):

Code:
set -o vi

... and then press the Esc key, followed by Ctrl+V.


Hope this helps.
# 11  
Old 12-28-2009
many thanks, that helped, and I also found out my version is Version M-11/16/88i Smilie
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