cannot get bash if command correct
Definite newbie problem
Code:
#!/bin/bash Quote:
What is it that I just cannot see? |
use space after 'if' and before '[', -eq NOT '=' for integers, space before ']', dont forget 'then' and 'fi'
|
Yes [ is actually a command so you need a space after if
On another side, if it is for testing integer, you can use bash arithmetic built-in Code:
if (( CREATE_TARGET_LIST == 1 )); then Code:
if(( CREATE_TARGET_LIST == 1 )); then |
what Keith said, for sure, but the biggest clue was
Code:
if[ 0 = 1]: command not found The bash interpreter depends heavily on the proper location of white space. In fact, I wouldn't expect that if statement to work if there really is no space between the 1 and the trailing ] |
Keith got me working.
keefaz: So the brackets are commands rather than grouping operators. Ok, That will take some getting accustomed to. On second thought: please explain the command that is embodied by: [ and ]. I presume the two characters taken together are the command with the entity between them being the argument. Thank you for your replies. Edit: interesting, and not in the good sense. I thought this was a good tutorial: https://ryanstutorials.net/bash-scri...statements.php But it does not mention the word spaces and does not describe what the posts here did. I need to find a better tutorial. |
Quote:
Code:
man test |
So I visited: man test with the result that I was and am unable to really understand what it is saying in the context of a bash if statement. I presume that man page makes sense to you guys, but from my novice perspective it does not help. So I will look for some more bash tutorials and bookmark one or two of them that discusses the bash if statement much better.
End result, I am much better off now than an hour ago. Thank you. |
|
grab a copy of the advanced bash scripting guide (abs) it may be in your distros repos, if not itz easy to find online, it covers all sorts from simple concepts upwards you will find it the best source of documentation for bash there is.
|
The one I referenced was easy to understand. But it left out a bunch of stuff. The site you, michaelk, suggested looks pretty good. Bash is more complicated than at first appears. (isn't everything)
Edit: The example Quote:
|
In bash we use a ; in place of a new line. The ; causes the preceding command to be executed before proceeding to the next command
|
All times are GMT -5. The time now is 07:02 AM. |