Read from file and execute the read command

Hi,

I am facing issues with the below:
I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,).

Now i want to read this command from file and execute it.
So my code below is :
Contents in the lookup.lkp file is :

c_e,m,a,`cd $BOX | ls cef_*|tail -1`,/home/me

In my shell script I read it as :

$(cat lookup.lkp | grep c_e | cut -d ',' -f4)

So above command should pick up

`cd $BOX | ls cef_*|tail -1`

which it does....but the command does not return the file name starting with cef_some_name even though there are files which match the wildcard.
Instead it quits using no such file or directory.

How can I execute this.Any help appreciated.

Try:

eval $(cat lookup.lkp | grep c_e | cut -d ',' -f4)

Hi,
Thanks for the reply.

But the above code does not help.
It gives the below error :

ls: cef_*: No such file or directory

Can you please help me out.

Two things to change in your lookup file:
a) don't pipe the cd $BOX to the next statement as it doen't make sense - cd has no output and ls doesn't read stdin.
b) strip the backticks off that entire command list; they make it try to execute the result of the ls, which is some cef_* file which is not executable.

Try sth like

c_e,m,a,cd $BOX ; ls cef_*|tail -1,/home/me

in the lookup file.

If the intention is to not run the ls cef_*|tail -1 if the cd $BOX failed, then use

cd $BOX && ls cef_*|tail -1

Hi Thanks for the replies.
But i have been getting the same error.
So in my lookup i have mentioned as

echo /a/b/c/box/$(ls -rt /a/b/c/box|grep -i cef |tail -1)

and to get this above stmt to execute and assign to ftf is :

ftf=$(eval $(cat $file_path | grep -i $STR | cut -d '*' -f4))

This is working for me....but as you can see in my lookup file i have hardcoded the path.
So the issue remains I have to parametrize this value.

Which could be :

echo $(ls -rt $BOX |grep -i cef |tail -1)

But this $BOX don't seem to resolve.I even tried \$BOX to resolve.
But it doesnt seem to resolve the value.

Can anyone please suggest some solution.

You lost me - sorry. What's the result of cat $file_path | grep -i $STR | cut -d '*' -f4 ?
Why don't you execute the relevant part of your code with the xtrace option on and post the result?

The variable $BOX is not defined, else its variable will appear in the error message!!