Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split Text Apart

Status
Not open for further replies.

Trancemission

Technical User
Oct 16, 2001
108
GB
I am attempting to write a script that will take a variable that is passed to it and then execute another program with that variable but only after I have managed to 'chop' the text up:

SOME_NAME(#,#) will be the variable that is passed to the script. The #'s will be different numbers but it will always be in the above format

I need it then to execute:

path/to/myprog SOME_NAME

Cheers

Marcus
 
You could do something like this ...

If the value of $1 in your script is SOME_NAME(1,2) you could do;

VAR1=`echo $1 | cut -d"(" -f1`
/path/to/myprog $VAR1

Greg.
 
Thats great, but I am still getting a couple of problems. My Script also uses AWK and my variables are getting messed up. Here is my script:

#! /usr/bin/sh
$msg=$2
$delay=$3
compname=`echo $1 | cut -d"(" -f1`
grep $compname customers | awk '{print $2}' > number
/testing/alarmpt $compname `cat number` "$msg" "$delay"

The problem is when I try to assign the values passed to the script to the variables $msg and $delay. If I don't do this, should awk return more that 1 result (it shouldn't but may do due to data integrity being up the spout it may do), awk will assign new values to $2 and $3 so I want to capture them into new variables before AWK excutes.

Your help is appreciated by this UNIX scripting novice who has been placed in the deep end :)

Cheers

 
At a first glance, lines 2 & 3 should be changed ...

#! /usr/bin/sh
msg=$2
delay=$3

compname=`echo $1 | cut -d"(" -f1`
grep $compname customers | awk '{print $2}' > number
/testing/alarmpt $compname `cat number` "$msg" "$delay"

You don't need to use the $ when assigning a value to a variable, only when you want to get the value. As you see it's correctly done the the compname assignment.

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top