Re: Q re: if test of command in bash script
Kent West wrote:
> Chris Jones wrote:
>
>> if mkdir; then
>> echo 'created OK'
>> else
>> echo 'not created OK'
>> exit 1
>>
>>
>> ... the [] is redundant, IOW:
>>
>> if test mkdir # ???
>>
>> also your sample has the then/else actions inverted.
>>
>>
>
> Thank you. I thought I had tried it without the brackets, but I must've
> introduced some other little problem when I tried it 'cause it works now.
>
> Steve Kemp suggested:
>
>
>> if ( mkdir -p $targetDir )
>>
>
> Do the parenths add any value? (meaning? readability? it seems to me to
> add readability)
>
> Thanks!
>
>
>
Hi,
There is another way of solving this issue. Use the format below:
if [ `mkdir -p $targetDir` ]
then
................
.......
fi
Thanks.
Regards,
Kurian.
Reply to: