PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > for a newbie to c shell setting a variable from echo output
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

for a newbie to c shell setting a variable from echo output

Réponse
 
LinkBack Outils de la discussion
Vieux 31/07/2007, 11h16   #1
DalUK
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut for a newbie to c shell setting a variable from echo output

Hello people

i have been stuck for over a day now on this one bit and i hope
someone out there can me.

i have a c shell script and basically i want to get the following
output into a variable for use further on in the script..

the output i want is generated from the below command

echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'


obviously if there is a better way then please advise but i need to
remove the last five characters from the ORACLE SID environment..

kind regards
Dal

  Réponse avec citation
Vieux 31/07/2007, 12h02   #2
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

DalUK wrote:
> Hello people
>
> i have been stuck for over a day now on this one bit and i hope
> someone out there can me.
>
> i have a c shell script and basically i want to get the following
> output into a variable for use further on in the script..
>
> the output i want is generated from the below command
>
> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'
>
>
> obviously if there is a better way then please advise but i need to
> remove the last five characters from the ORACLE SID environment..
>
> kind regards
> Dal
>


Posix shells:

echo "${ORACLE_SID%?????}"

All shells:

expr x"$ORACLE_SID" : x"\(.....\)"



--
Michael Tosch @ hp : com
  Réponse avec citation
Vieux 31/07/2007, 12h02   #3
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

DalUK wrote:
> Hello people
>
> i have been stuck for over a day now on this one bit and i hope
> someone out there can me.
>
> i have a c shell script and basically i want to get the following
> output into a variable for use further on in the script..
>
> the output i want is generated from the below command
>
> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'
>
>
> obviously if there is a better way then please advise but i need to
> remove the last five characters from the ORACLE SID environment..
>
> kind regards
> Dal
>


Posix shells:

echo "${ORACLE_SID%?????}"

All shells:

expr x"$ORACLE_SID" : x"\(.....\)"



--
Michael Tosch @ hp : com
  Réponse avec citation
Vieux 31/07/2007, 12h04   #4
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

Michael Tosch wrote:
> DalUK wrote:
>> Hello people
>>
>> i have been stuck for over a day now on this one bit and i hope
>> someone out there can me.
>>
>> i have a c shell script and basically i want to get the following
>> output into a variable for use further on in the script..
>>
>> the output i want is generated from the below command
>>
>> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'
>>
>>
>> obviously if there is a better way then please advise but i need to
>> remove the last five characters from the ORACLE SID environment..
>>
>> kind regards
>> Dal
>>

>
> Posix shells:
>
> echo "${ORACLE_SID%?????}"
>
> All shells:
>
> expr x"$ORACLE_SID" : x"\(.....\)"


Oops, the latter should be

expr x"$ORACLE_SID" : x"\(.*\)....."


--
Michael Tosch @ hp : com
  Réponse avec citation
Vieux 31/07/2007, 12h04   #5
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

Michael Tosch wrote:
> DalUK wrote:
>> Hello people
>>
>> i have been stuck for over a day now on this one bit and i hope
>> someone out there can me.
>>
>> i have a c shell script and basically i want to get the following
>> output into a variable for use further on in the script..
>>
>> the output i want is generated from the below command
>>
>> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'
>>
>>
>> obviously if there is a better way then please advise but i need to
>> remove the last five characters from the ORACLE SID environment..
>>
>> kind regards
>> Dal
>>

>
> Posix shells:
>
> echo "${ORACLE_SID%?????}"
>
> All shells:
>
> expr x"$ORACLE_SID" : x"\(.....\)"


Oops, the latter should be

expr x"$ORACLE_SID" : x"\(.*\)....."


--
Michael Tosch @ hp : com
  Réponse avec citation
Vieux 31/07/2007, 12h41   #6
Maxwell Lol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

DalUK <msn.dal@gmail.com> writes:

> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'


echo $ORACLE_SID | sed 's/.....$//s'
  Réponse avec citation
Vieux 31/07/2007, 12h41   #7
Maxwell Lol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

DalUK <msn.dal@gmail.com> writes:

> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'


echo $ORACLE_SID | sed 's/.....$//s'
  Réponse avec citation
Vieux 31/07/2007, 12h47   #8
DalUK
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

On 31 Jul, 12:02, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote:
> DalUK wrote:
> > Hello people

>
> > i have been stuck for over a day now on this one bit and i hope
> > someone out there can me.

>
> > i have a c shell script and basically i want to get the following
> > output into a variable for use further on in the script..

>
> > the output i want is generated from the below command

>
> > echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'

>
> > obviously if there is a better way then please advise but i need to
> > remove the last five characters from the ORACLE SID environment..

>
> > kind regards
> > Dal

>
> Posix shells:
>
> echo "${ORACLE_SID%?????}"
>
> All shells:
>
> expr x"$ORACLE_SID" : x"\(.....\)"
>
> --
> Michael Tosch @ hp : com- Hide quoted text -
>
> - Show quoted text -




Hi, the echo "${ORACLE_SID%?????}" works and is much shorter than what
i had however i still cannot seem to get the write syntax in c
shell to get that output into a variable, is this something you would
be able to assist me with

thanks
Dal

  Réponse avec citation
Vieux 31/07/2007, 12h47   #9
DalUK
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

On 31 Jul, 12:02, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote:
> DalUK wrote:
> > Hello people

>
> > i have been stuck for over a day now on this one bit and i hope
> > someone out there can me.

>
> > i have a c shell script and basically i want to get the following
> > output into a variable for use further on in the script..

>
> > the output i want is generated from the below command

>
> > echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'

>
> > obviously if there is a better way then please advise but i need to
> > remove the last five characters from the ORACLE SID environment..

>
> > kind regards
> > Dal

>
> Posix shells:
>
> echo "${ORACLE_SID%?????}"
>
> All shells:
>
> expr x"$ORACLE_SID" : x"\(.....\)"
>
> --
> Michael Tosch @ hp : com- Hide quoted text -
>
> - Show quoted text -




Hi, the echo "${ORACLE_SID%?????}" works and is much shorter than what
i had however i still cannot seem to get the write syntax in c
shell to get that output into a variable, is this something you would
be able to assist me with

thanks
Dal

  Réponse avec citation
Vieux 31/07/2007, 13h22   #10
google@kenbeer.info
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

On Jul 31, 6:16 am, DalUK <msn....@gmail.com> wrote:
> Hello people
>
> i have been stuck for over a day now on this one bit and i hope
> someone out there can me.
>
> i have a c shell script and basically i want to get the following
> output into a variable for use further on in the script..
>
> the output i want is generated from the below command
>
> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'
>
> obviously if there is a better way then please advise but i need to
> remove the last five characters from the ORACLE SID environment..
>
> kind regards
> Dal


It sounds like you want to chop off the last five characters of
$ORACLE_SID. First of all, you're not testing to see what happens if
$ORACLE_SID is 5 characters or fewer. I'll assume you're doing that
elsewhere.

A simpler way to do what you want to do it this:

echo $ORACLE_SID | sed 's/.....$//'

In other words, replace five characters anchored to the end of the
string with null. Note that unlike the awk technique you used, if
ORACLE_SID has fewer than 5 characters, it isn't changed. You still
have a problem if ORACLE_SID is exactly 5 characters.

To get the result into another variable, use backticks -> ``

setenv NEWVAR `echo $ORACLE_SID | sed 's/.....$//'`

There are other ways of course, and I would recommend using a borne-
shell like shell such as ksh or bash instead of csh.

Good luck

Ken Beer

  Réponse avec citation
Vieux 31/07/2007, 17h38   #11
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

DalUK wrote:
> On 31 Jul, 12:02, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
> wrote:
>> DalUK wrote:
>>> Hello people
>>> i have been stuck for over a day now on this one bit and i hope
>>> someone out there can me.
>>> i have a c shell script and basically i want to get the following
>>> output into a variable for use further on in the script..
>>> the output i want is generated from the below command
>>> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'
>>> obviously if there is a better way then please advise but i need to
>>> remove the last five characters from the ORACLE SID environment..
>>> kind regards
>>> Dal

>> Posix shells:
>>
>> echo "${ORACLE_SID%?????}"
>>
>> All shells:
>>
>> expr x"$ORACLE_SID" : x"\(.....\)"
>>
>> --
>> Michael Tosch @ hp : com- Hide quoted text -
>>
>> - Show quoted text -

>
>
>
> Hi, the echo "${ORACLE_SID%?????}" works and is much shorter than what
> i had however i still cannot seem to get the write syntax in c
> shell to get that output into a variable, is this something you would
> be able to assist me with
>


Posix shell:

var=${ORACLE_SID%?????}
echo "$var"

C-shell:

set var=`expr x"$ORACLE_SID" : x"\(.*\)....."`
echo "$var"


--
Michael Tosch @ hp : com
  Réponse avec citation
Vieux 31/07/2007, 18h07   #12
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

On 2007-07-31, DalUK wrote:
> Hello people
>
> i have been stuck for over a day now on this one bit and i hope
> someone out there can me.
>
> i have a c shell script and basically i want to get the following
> output into a variable for use further on in the script..
>
> the output i want is generated from the below command
>
> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'
>
>
> obviously if there is a better way then please advise but i need to
> remove the last five characters from the ORACLE SID environment..


In a POSIX shell (bash, ksh, etc.), you can use parameter
expansion:

ORACLE_SID=${ORACLE_SID%?????}


Csh is not recommended for scripting.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 31/07/2007, 19h57   #13
DalUK
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

On 31 Jul, 17:38, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote:
> DalUK wrote:
> > On 31 Jul, 12:02, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
> > wrote:
> >> DalUK wrote:
> >>> Hello people
> >>> i have been stuck for over a day now on this one bit and i hope
> >>> someone out there can me.
> >>> i have a c shell script and basically i want to get the following
> >>> output into a variable for use further on in the script..
> >>> the output i want is generated from the below command
> >>> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'
> >>> obviously if there is a better way then please advise but i need to
> >>> remove the last five characters from the ORACLE SID environment..
> >>> kind regards
> >>> Dal
> >> Posix shells:

>
> >> echo "${ORACLE_SID%?????}"

>
> >> All shells:

>
> >> expr x"$ORACLE_SID" : x"\(.....\)"

>
> >> --
> >> Michael Tosch @ hp : com- Hide quoted text -

>
> >> - Show quoted text -

>
> > Hi, the echo "${ORACLE_SID%?????}" works and is much shorter than what
> > i had however i still cannot seem to get the write syntax in c
> > shell to get that output into a variable, is this something you would
> > be able to assist me with

>
> Posix shell:
>
> var=${ORACLE_SID%?????}
> echo "$var"
>
> C-shell:
>
> set var=`expr x"$ORACLE_SID" : x"\(.*\)....."`
> echo "$var"
>
> --
> Michael Tosch @ hp : com- Hide quoted text -
>
> - Show quoted text -




Thats the puppy thank you very very much... i can sleep tonight
now ;-)
regards
Dal

  Réponse avec citation
Vieux 31/07/2007, 19h57   #14
DalUK
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for a newbie to c shell setting a variable from echo output

On 31 Jul, 17:38, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
wrote:
> DalUK wrote:
> > On 31 Jul, 12:02, Michael Tosch <eed...@NO.eed.SPAM.ericsson.PLS.se>
> > wrote:
> >> DalUK wrote:
> >>> Hello people
> >>> i have been stuck for over a day now on this one bit and i hope
> >>> someone out there can me.
> >>> i have a c shell script and basically i want to get the following
> >>> output into a variable for use further on in the script..
> >>> the output i want is generated from the below command
> >>> echo $ORACLE_SID | awk '{printf("%s\n",substr($1,1,(length($1)-5)))}'
> >>> obviously if there is a better way then please advise but i need to
> >>> remove the last five characters from the ORACLE SID environment..
> >>> kind regards
> >>> Dal
> >> Posix shells:

>
> >> echo "${ORACLE_SID%?????}"

>
> >> All shells:

>
> >> expr x"$ORACLE_SID" : x"\(.....\)"

>
> >> --
> >> Michael Tosch @ hp : com- Hide quoted text -

>
> >> - Show quoted text -

>
> > Hi, the echo "${ORACLE_SID%?????}" works and is much shorter than what
> > i had however i still cannot seem to get the write syntax in c
> > shell to get that output into a variable, is this something you would
> > be able to assist me with

>
> Posix shell:
>
> var=${ORACLE_SID%?????}
> echo "$var"
>
> C-shell:
>
> set var=`expr x"$ORACLE_SID" : x"\(.*\)....."`
> echo "$var"
>
> --
> Michael Tosch @ hp : com- Hide quoted text -
>
> - Show quoted text -




Thats the puppy thank you very very much... i can sleep tonight
now ;-)
regards
Dal

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h26.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,24432 seconds with 22 queries