Shell script variable parsing

Shell script variable parsing

Post by Tim Vorce CT/ » Wed, 26 Oct 1994 22:05:51



My apologies if this is not the right place to post.  I'm interested in
parsing a variable to strip off the first 3 characters, in order to make a
decision in the script.  There is a function in the Korn Shell to do that
(typeset).  However, this environment is a sun platform, and I've been told
that that functionality isn't available in the Bourne or C shells.  
Does anybody know of an equivalent construct in those shell???
 
 
 

Shell script variable parsing

Post by Mark Walla » Sat, 29 Oct 1994 22:15:19



|> My apologies if this is not the right place to post.  I'm interested in
|> parsing a variable to strip off the first 3 characters, in order to make a
|> decision in the script.  There is a function in the Korn Shell to do that
|> (typeset).  However, this environment is a sun platform, and I've been told
|> that that functionality isn't available in the Bourne or C shells.  
|> Does anybody know of an equivalent construct in those shell???

How about just using "cut":

% cat first3
#!/bin/sh
# isolate 1st 3 chars of arg 1

first3=`echo $1 | cut -c1-3`
rest=`echo $1 | cut -c4-`

echo first3:$first3:
echo rest:$rest:

% first3 hello
first3:hel:
rest:lo:
%

--
Mark Wallace
Harris Corporation, Electronic Systems, Melbourne, Florida, USA


 
 
 

1. How to pass a variable from a shell script to another shell script...

Hi,
         I have written a shell script 1............and internally its
calling another shell script 2........input to  redhat specific
chkconfig command... which executes and builds links in bootstartup
scipt directories (rc.d).

Actually i needs to pass a variable $DIRECTORY  of my command available
( can hard code but i am
setting it in the 1st script) to the 2nd script how to pass that... As
the setting is happening before the calling of
shell script2, i just tried like putting  echo "$DIRECTORY" into the 2nd
shell script, which is not working is there
a way to get the functionality.

shellscript1:
#!/bin/sh
---------
---------
---------
DIRECTORY="/sbin/ntp"
---------
---------
/sbin/chkconfig "shellscript2"
---------

shellscript2:
#!/bin/sh
-------
echo "$DIRECTORY"     <------put to see whether getting the value here
or not..

$DIRECTORY   -c ntp.conf          <------if it is so ,  i could use like
this.................

thanks,
srinivas.

--
office ph: 091-40-3607619

2. Anyone using a Byterunner serial card ?

3. c shell script; Howto use environement variables to build environment variables and take their value

4. math calculation? urgent please help

5. file contents into variable, or global variable from shell script

6. xquake - segmentation fault in Linux 1.3.20

7. Bourne shell variable parsing

8. Xinerama and ATI Rage PRO as secondary monitor

9. Parsing out environment variable in c-shell

10. export variables to calling shell in a shell-script

11. Why my shell don't parse the variable?

12. export variables to calling shell in a shell-script

13. Shell Variables: Shell prompt OK, script, NO.