calling multiple functions from within if statement - cannot get it to work
Hi.
I have this sample/training bash file that is supposed to check username and computer name. There is something making this bash file not working correctly. But I'm not able to figure exact what that is. I've put comments in the script to explain the problem(s) Code:
#!/bin/bash |
"[ expression ]" is an alias for "test expression" which evaluates an expression, not a command.
To evaluate the exit status of a command, remove the brackets. See: //www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html //www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html#index-test Also, using ShellCheck to identify issues is always a good idea. |
Quote:
It seems to work better now, but it still doesn't work as intended: Updated code (only line 38 is edited) Code:
#!/bin/bash
|
In other words, a function is like a command.
And the if takes a command. Code:
if staticControlUsername && staticControlMachineName You can as well return the exit status of a true/false command. Code:
true; return Code:
false; return |
Quote:
Quote:
|
Quote:
So the misconception I have is coming from earlier (a life before Linux) I played around with Authohotkey script and the wbs script that was including in MS os. In those script languages, any call to a function, where the call is part of an if-statement, is normally treated as true for any number or non-zero strings. And this use for function calls therefore follows other rules. |
Code:
#!/bin/bash |
Putting the function declaration within an if statement is new for me. I think I must try to wrap my mind around this now
|
Quote:
|
Quote:
I am having printpassbook.sh shell script from 2003 till now. Before modification I used to take a backup of that file After modification I used to gzip that backup file. printpassbook.sh used to display: 1) my post office transactions (incoming/outgoing +/- four days from today 2) available balance that I can withdraw excluding recurring deposit amount and MAB 3) MIS interest I am going to receive tomorrow and day after tomorrow 4) my total salary from MIS at post office for current month 5) waiting day/month/years at RD/MIS accounts. 6) displaying related colors based on date/waiting day/month/years. Remember to take backup before modification for maintenance. |
I'm with pan64 - don't do that ;)
|
All times are GMT -5. The time now is 05:58 AM. |