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 have the most basic bash script, that is also unfortunately producing the most elementary of error messages!
Basically the purpose is to create a number of directories performing a similar calculation in each.
Quote:
#!/bin/bash
for (( a = 2 ; a <= 7 ; a++ )) ; do
mkdir $a
cp Si2.param $a
cd $a
cat >Si2.cell <<!
%block lattice_cart
$a $a 0.0
$a 0.0 $a
0.0 $a $a
%endblock lattice_cart
%block positions_frac
Si 0.00 0.00 0.00
Si 0.25 0.25 0.25
%endblock positions_frac
!
cd ..
done
I checked that my syntax is correct for a for loop of this kind.
Whether this or another issue, I get the standard error message
./lattice_const_iter.sh: line 22: syntax error: unexpected end of file
Is it possible this has anything to do with being on a mac? I recently installed macports and a number of basic bash environment commands stopped working, next to their equivalents in mac ports, for example, -apt-get- .
Is the execution form ./ always the same?
Or is there something unnoticed in my script?
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,795
Rep:
Quote:
Originally Posted by botleybat
./lattice_const_iter.sh: line 22: syntax error: unexpected end of file
I get that a lot.
What I found curious about this message is that you don't seem to have 22 -- or even 21 -- lines in the script. I pasted it into an editor and only see 19 lines.
Quote:
Is it possible this has anything to do with being on a mac? I recently installed macports and a number of basic bash environment commands stopped working, next to their equivalents in mac ports, for example, -apt-get- .
Interesting but I'm doubting that the macports package broke your script but I haven't used that on MacOS. Were there release notes that told you what behaviors you could expect? I can't imagine that it would break basic shell function.
Quote:
Is the execution form ./ always the same?
You mean the "./lattice_const_iter.sh" command line? Yes... that's going to be needed if your current subdirectory -- the one where the script resides -- is not in your shell's PATH setting. (And, BTW, you really don't want that; it's a security thing.)
Quote:
Or is there something unnoticed in my script?
Well, I didn't see anything but this error message usually means there's something structurally incorrect with the script: an unclosed quoted string, missing bracket/brace/parenthesis. If you're using vim -- which is, as I recall, included with MaxOS -- or Emacs (separate package), you can enable syntax and expression highlighting that sometimes help you see these types of errors. Careful, though: I've seen messages that say there was a problem with a missing double-quote when it was actually something unrelated like "if [[ blah blah ]; then", i.e., missing ")" or "${VARNAME]".
Style comment: I'd use something like "EOD" instead of "!" in your here-script. Easier to see.
Your script, as you posted it, works just fine here (Ubuntu 14.04, bash 4.3.11).
As @rnturn mentioned, you probably stripped some lines (comments?) before posting -- they may be an issue.
What I found curious about this message is that you don't seem to have 22 -- or even 21 -- lines in the script. I pasted it into an editor and only see 19 lines.
Correct. The script is not 22 lines long; so perhaps there is garbage in the file.
Put "set -xv" as your second line in the script and this will enable more verbose output. Perhaps this will show you what the erroneous line #22 contains and give some insight into what the script is doing when it encounters this line.
Is it possible this has anything to do with being on a mac? I recently installed macports and a number of basic bash environment commands stopped working, next to their equivalents in mac ports, for example, -apt-get- .
...there seem to be some misconceptions about "basic bash commands" - apt-get surely isn't one and i'm not at all surprised to hear that it does "not work" on a mac.
and what exactly, botleybat, did you mean by this:
Quote:
Is the execution form ./ always the same?
...in any case, i think you should read "man bash" and compare it to online versions of bash's man page (which are likely to be for a standard linux environment).
also, for us to help you, the output of
Code:
bash --version
might shed some (first) light on this.
=============================================
edit:
script works here too (bash 4.3).
since it is short enough -
please put "set -xv"
right beneath the initial "#!/bin/bash"
and run the script.
copy-paste the output you get here.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.