Ok, I'm trying to understand something. I've done some searches, but couldn't find anything definitive.
Now, I have come across a few things around the web cautioning against "eval", so that's duly noted, and any advice to alternative methods is greatly appreciated
So, easiest thing is probably a simple example:
I have the following 3 scripts setup:
a quick chmod to make sure they are executable ...
Then I call main:
Output is:
So, main can see the function, however, the called script cannot?
Can anyone suggest a way to do this?
In case it's not obvious, I am passing a script to another (wrapper) script (ie think framework).
So the "main" script will handle some common setup/logs/etc., then run the passed script.
This isn't designed for interactive users, it's for a backend batch framework.
Should I be using the "eval" in this manner? or is there another command/option to ensure the functions can be handled?
So far, variables have worked just fine, but I only hit this with the function declarations.
Thanks!
(I'm on Sun Unix 5.10, however, any (mostly?) generic method of doing this would be appreciated)
Your first shell script is defining a function and after that it knows about that function. But other shell scripts do not. Each shell script must define its own functions.
Your first shell script is defining a function and after that it knows about that function. But other shell scripts do not. Each shell script must define its own functions.
You could source the second script with the . command. Then the 2nd script runs in the first process. However the second script is really just some commands (like your .profile file is). It is not really a script.
You could source the second script with the . command. Then the 2nd script runs in the first process. However the second script is really just some commands (like your .profile file is). It is not really a script.
Oh that's a thought - hadn't even thought about doing that.
However, as you say, "it's not really a script" ... so if that second script IS intended as a full script - that's not a good way of doing that, though, is it?
I believe that a script should stand on its own two feet. It should not require helper script to preset an environment for it. If it needs functions, it should seek them out and install them. It should set the PATH variable if it needs anything special. And the same with any other environment variable. We get a a lot of threads about a script that works from the command line but fails as a cron job. That never happens with a first class script.
These 2 Users Gave Thanks to Perderabo For This Post:
I believe that a script should stand on its own two feet. It should not require helper script to preset an environment for it. If it needs functions, it should seek them out and install them. It should set the PATH variable if it needs anything special. And the same with any other environment variable. We get a a lot of threads about a script that works from the command line but fails as a cron job. That never happens with a first class script.
Yeah, I understand. I've hit that in previous places I worked. So with this, that's kind of what I'm trying to avoid Trying to make sure everything's set up front.
Function list wasn't a must have, so I'll handle it more traditional.
I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line
if
then... (8 Replies)
Hello All,
Since my variables are nested I use eval to populate the data.
I have an ambiguity here when eval is used along with &
say I have the below variable
url="www.unix.com" , this come from function call as argument.
I want to take this into another variable say... (6 Replies)
Hi all,
some small script with eval turned me to crazy.
my OS is linux
Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux
below script works well
#!/bin/bash
eval ssh remotehost date
eval ssh remotehost ls
below... (1 Reply)
hi all,
Am trying to add some code to a ksh script and i dont understand how an eval function is used :
_var=$1
_conceal=$2
eval _val=\$${_var}
can someone shed some light on what the eval function in the above context means/does ??
thanks. (4 Replies)
I am trying to expand the variable $user in my alias command and tried
several variations of eval but can't seem to get it to work.
The end result should be either:
oracle_user='sudo su - oracle ' or oracle_user='sudo su - oracle1 '
user=$(grep '^oracle:' /etc/passwd | cut... (5 Replies)
Hi All,
I'm running some encrypted data through a script I wrote. In order to do this, I'm using eval to resolve some of my variables. At the moment, when I use eval to resolve, it strips out some of my encrypted values, and totally drops some others. For example if I have the value ab1"3 it drops... (1 Reply)
My script has the following for loop in it.
foreach id (CLKM4 DGTM4 GNNM4)
eval echo $id \$${id}sf \$${id}sfk
end
so "id" is a variable defined in the loop, and "idsf" and "idsfk" are variables defined in another part of the script, they return values of 0 or more. The problem i'm... (2 Replies)