1752649 Members
5781 Online
108788 Solutions
New Discussion юеВ

Re: variable in if

 
SOLVED
Go to solution
Gemini_2
Regular Advisor

Re: variable in if

yes, yes, your answer is correct.

it was very closed to what I had, but I placed my quote place wrong.

thanks for your help!

ps: you also dont need the ":=", you only need "="
James R. Ferguson
Acclaimed Contributor

Re: variable in if

Hi (again) Gemini:

I too had concocted a solution identical to by Dennis'. It would seem to be correct (using '=' instead of the ALGOL assignment ':=' operator) and yet failed/fails for me:

# [ -z "${LIST=$(ls -1 /tmp/gemini* 2>/dev/null})" ] && echo "empty" || echo ${LIST}

This does not yield any results for me; rather it gives and empty list. Comments, gentlemen?

Regards!

...JRF...
Gemini_2
Regular Advisor

Re: variable in if

oh, he had a little typo in his statement..
I corrected in my script, but I didnt point it out.

this should be right.

[ -z "${LIST=$(ls -1 /tmp/gemini* 2>/dev/null)}" ] && echo "empty" || echo ${LIST}
Dennis Handly
Acclaimed Contributor

Re: variable in if

I made a typo, swap the "}" and ")":
[ -z "${LIST:=$(ls -1 /tmp/gemini* 2>/dev/null)}" ]

>you also don't need the ":=", you only need "="

Yes, only because $LIST must NOT be set at all.

>JRF: This does not yield any results for me; rather it gives and empty list. Comments, gentlemen?

Did you do this as root? You have created a file in /dev: null}

James R. Ferguson
Acclaimed Contributor

Re: variable in if

Hi Gemini & Dennis:

Aahhaa! Yes, OK.

> Dennis: I made a typo, swap the "}" and ")":

Oh, OK, I kept missing that :-{

> Dennis: Did you do this as root? You have created a file in /dev: null}

And, again, yes! I did and I had a file in '/dev/' so named.

Very nice solution, Dennis.

Regards!

...JRF...