Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi guys
I'm having a problem trying to use && clause in the if command. If I use the && command in the if clause, it keeps prompting me for a missing ']'. I've attached my if command here, hope anyone can help me.
if [ -z "`ls $LOG`" && -z "`ls $BACKUP`" ] ; then
echo "Empty"
else
echo "Nt Empty"
fi
Another question. I've put the above into a bash file and executed from the command prompt. But it always gives me the error "syntax error: unexpected end of file". But if I were to run the if else statements on the command line, I don't get any error. Any idea?
No, the assignments to $LOG and $BACKUP seem just fine to me.
Can you then please post the complete code?
The "unexpected end of file" error usually occurs when
a block (ie "if", "for", etc) isn't terminated properly
(even if it doesn't seem to be at first sight).
No, the assignments to $LOG and $BACKUP seem just fine to me.
Can you then please post the complete code?
The "unexpected end of file" error usually occurs when
a block (ie "if", "for", etc) isn't terminated properly
(even if it doesn't seem to be at first sight).
Here is code -
#!/bin/bash
LOG=/opt/oracle/logs
BACKUP=/backup/oracle
if [ -z "`ls $LOG`" ] && [ -z "`ls $BACKUP`" ] ; then
echo "Empty";
else
echo "Nt Empty";
fi
exit
I'm guessing you have a control character in there somewhere, cause for me there is no such error:
Quote:
[chakkerz@tigerente ~]$ ./test
ls: /opt/oracle/logs: No such file or directory
ls: /backup/oracle: No such file or directory
Empty
[chakkerz@tigerente ~]$ cat test
#!/bin/bash
LOG=/opt/oracle/logs
BACKUP=/backup/oracle
if [ -z "`ls $LOG`" ] && [ -z "`ls $BACKUP`" ] ; then
echo "Empty";
else
echo "Nt Empty";
fi
exit
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.