ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I'm trying to make a script that prints a list of services and drives etc and their status.
It outputs various services status in color. Fx. "up" colored green if running and "down" colored red if not running. That works perfectly when using echo - but when I'm using printf, it just shows everything in green - even if it's down. I checked the scripts colorcodes but can't find the error. See attached file.
The first usage of variables chkapace, chksamba is prefixed with $, the second isn't (check your if-statements).
And in test, it is not ==, use either = (strings) or -eq (numbers)
The first usage of variables chkapace, chksamba is prefixed with $, the second isn't (check your if-statements).
And in test, it is not ==, use either = (strings) or -eq (numbers)
Thanks! It seems to be working now. I corrected all the if statements to use = instead of == and corrected some variables as you pointed out might be the problem.
I have another question about alignment I hope you can answer as well :-)
Right now the script left-aligns the first column and right-aligns the second and third. I would like it to left-align the second/mid column - but how to do that?
Right now the script left-aligns the first column and right-aligns the second and third. I would like it to left-align the second/mid column - but how to do that?
Have not too much experiences with echo -e and even fewer with printf . but it seems simply missing something like
COLS_PER_COL=15
The variable would be set to "" or "0" if not declared .
test should work with '==' because it would also work with '!=' .
'==' and '=' spits fewer error messages than '-eq','-lt','-ge',... because they can match a char or string also .
it is also advisable to double quote the first value in a test comparison for a number in case the string is empty .
Code:
a=
if [ $a = "0" ];then echo 'a is 0';fi
bash: [: =: unary operator expected
if [ "$a" = "0" ];then echo 'a is 0';fi
a=a
if [ $a -gt 0 ];then echo 'a is greater than 0';fi
bash: [: a: integer expression expected
> Right now the script left-aligns the first column and right-aligns the second and third. I would like it to left-align the second/mid column - but how to do that?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.