what is that?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users what is that?
# 1  
Old 10-17-2002
what is that?

x=$([ -x /etc/get_tape ] && echo /etc/get_tape; [ -x /abc/prog/bin/get_tape ] && echo /abc/prog/bin/get_tape)

Smilie
# 2  
Old 10-17-2002
This is a script.

x=$([ -x /etc/get_tape ] && echo /etc/get_tape; [ -x /abc/prog/bin/get_tape ] && echo /abc/prog/bin/get_tape)

the x is a variable

-x test if /etc/get_tape is excutable
&& (than) if /etc/get_tape is executable that is true echo the containent of /etc/get_tape.

the same applies to -x /abc/prog/bin/get_tape
# 3  
Old 10-17-2002
please correct me if I'm wrong...

echo /etc/get_tape just echoes the same literal string /etc/get_tape back..

there are two such echoes in between the parenthesis which execute under condition and which just echo path strings...

I still didn't get how the $(...;...) construct works... and what result would be assigned to the variable x?

Will try this but would like to know what the experts here would say...

Thank you!
Vishnu.
# 4  
Old 10-17-2002
Well semicolon lets you put two command on one line like this:
date ; uname -a

And $( ) sets x to the output of the command so x=`date` and x=$(date) do the same thing.

What the posted command is trying to do is to set x to the path of the get_tape routine. If get_tape does not exist in either place, x is null. If get_tape exists in exactly one of the places, x is that path.

But if get_tape exists in both places, x will be a two-line value with both paths in it. I wonder if the author of the code realizes that. Maybe that's what he wanted. Restricting the value of x to a single line would make this ugly construct even worse:
x=$([ -x /etc/get_tape ] && echo /etc/get_tape || { [ -x /abc/prog/bin/get_tape ] && echo /abc/prog/bin/get_tape; })

Personally, I think this really calls for explicit "if" statements. Then the code is much clearer, and much easier to maintain. But sometimes it is fun to crank out these opaque one-liners and I'm not really in a position to be casting too many stones here. Smilie
# 5  
Old 10-17-2002
MySQL thank you

Thank you all very much for your help.. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question