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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to ececute a script within a script given in the parameters

Status
Not open for further replies.

Larshg

Programmer
Mar 1, 2001
187
DK
Hi

I am trying to execute a script from within another script - the script that should be executede is given as parameters.

ex.
parm_test.sh "[/home/nmsuser/scripts/Workflow.sh -=-CRM 2B - IVR-=-"

should execute this script and commands
/home/nmsuser/scripts/Workflow.sh "CRM 2B - IVR"|awk 'NF'


This is a very simplified version of the script that shows the problem
#!/bin/ksh

#the following gsub -=- with " and =-= with '
TestCase=`echo $1|awk -F "[" '{print $2}'|awk -F "]" '{print $1}'|awk '{gsub("-=-","\"",$0); print }'|awk '{gsub("=-=","\047",$0); print }'`

echo $TestCase

chk=`$TestCase`
echo $chk

#end

the echo works and looks fine - I can se that the gsub worked - it echo's
/home/nmsuser/scripts/Workflow.sh "CRM 2B - IVR"|awk 'NF'

whitch is excacly what I want executede - and it I hard code it into the script it works fine.
 
sorry - pressed submit by mistake(whantede to add this)

the chk does not work - it doesn't ececute the script

The reason for the gsub was that I couldn't get it to work and I thougt that was the problem. - maby I was mistaken

Hope someone can help

Larshg
 
Have you tried this ?
chk=`eval $TestCase`

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Great it works

What does eval do?

$ man eval
No manual entry for eval.


/Larshg
 
From the Solaris 8 man page:

User Commands exec(1)



NAME
exec, eval, source - shell built-in functions to execute
other commands

SYNOPSIS
sh
exec [ argument ... ]

eval [ argument ... ]

csh
exec command

eval argument ...

source [ -h ] name

ksh
*exec [ arg ... ]

*eval [ arg ... ]

DESCRIPTION
sh
The exec command specified by the arguments is executed in
place of this shell without creating a new process.
Input/output arguments may appear and, if no other arguments
are given, cause the shell input/output to be modified.

The arguments to the eval built-in are read as input to the
shell and the resulting command(s) executed.

csh
exec executes command in place of the current shell, which
terminates.

eval reads its arguments as input to the shell and executes
the resulting command(s). This is usually used to execute
commands generated as the result of command or variable sub-
stitution.

source reads commands from name. source commands may be
nested, but if they are nested too deeply the shell may run
out of file descriptors. An error in a sourced file at any
level terminates all nested source commands.

-h Place commands from the file name on the history list
without executing them.

ksh
With the exec built-in, if arg is given, the command speci-
fied by the arguments is executed in place of this shell



SunOS 5.8 Last change: 15 Apr 1994 1






User Commands exec(1)



without creating a new process. Input/output arguments may
appear and affect the current process. If no arguments are
given the effect of this command is to modify file descrip-
tors as prescribed by the input/output redirection list. In
this case, any file descriptor numbers greater than 2 that
are opened with this mechanism are closed when invoking
another program.

The arguments to eval are read as input to the shell and the
resulting command(s) executed.

On this man page, ksh(1) commands that are preceded by one
or two * (asterisks) are treated specially in the following
ways:

1. Variable assignment lists preceding the command remain in
effect when the command completes.

2. I/O redirections are processed after variable assign-
ments.

3. Errors cause a script that contains them to abort.

4. Words, following a command preceded by ** that are in the
format of a variable assignment, are expanded with the
same rules as a variable assignment. This means that
tilde substitution is performed after the = sign and word
splitting and file name generation are not performed.

ATTRIBUTES
See attributes(5) for descriptions of the following attri-
butes:

____________________________________________________________
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
| Availability | SUNWcsu |
|_____________________________|_____________________________|


SEE ALSO
csh(1), ksh(1), sh(1), attributes(5)
 
You can do all the work into a single awk command instead of four :
[tt]
TestCase=`echo $1|awk '{
sub(/^[^[]*\[/,"");
sub(/][^]]*$/,"");
gsub("-=-","\"",$0) ;
gsub("=-=","\047",$0)
}'`
chk=`eval $TestCase`
[/tt]
The same thing with sed :
[tt]
TestCase=`echo $1 | sed -e 's/[^[]*\[\(.*\)\][^]]*/\1/' -e 's/-=-/"/g' -e "s/=-=/'/g"`
chk=`eval $TestCase`
[/tt]

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top