Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's 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.
#!/bin/bash
...
CREATE_TARGET_LIST=0
...
if[ $CREATE_TARGET_LIST = 1 ]
then
and the response is
Quote:
./find.sh: line 65: if[ 0 = 1]: command not found
./find.sh line 66: syntax error near unexpected token 'then'
./find.sh line 66: 'then'
I have tried ==, -eq, removed all the white space and get the same response. It shows line 66 for the error and I have commented out all the code above this fragment except for the she-bang and the variable creation.
what Keith said, for sure, but the biggest clue was
Code:
if[ 0 = 1]: command not found
which shows that the interpreter was seeing the if[ 0 = 1]as a single command.
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:
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.
I suggest to read the manual page for the test command, it should explain thing better then me
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.
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,151
Rep:
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:
if [ -r somefile ]; then
The concept of putting the semicolon after the close bracket is a major contradiction with writing C code.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.