LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2016, 11:14 AM   #1
botleybat
LQ Newbie
 
Registered: Oct 2016
Posts: 4

Rep: Reputation: Disabled
elementary bash script failure


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?
 
Old 10-12-2016, 12:42 PM   #2
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,795

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by botleybat View Post
./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.
 
Old 10-12-2016, 01:21 PM   #3
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

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.
 
Old 10-12-2016, 01:25 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
If you change your quote tags to code tags your formatting will be kept

Try placing set -xv at the start of your script (second line) and check the output.
 
Old 10-13-2016, 12:51 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,876
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by rnturn View Post
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.
 
1 members found this post helpful.
Old 10-14-2016, 03:45 AM   #6
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Is it possible there is a problem with using '!' as the EOF for the cat command?
 
Old 10-16-2016, 04:10 AM   #7
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
^ yes, i was thinking that too.

but then...
Quote:
Originally Posted by botleybat View Post
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.

Last edited by ondoho; 10-16-2016 at 04:18 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Elementary Luna 'grub-efi package' Installation Failure anon288 Linux - Newbie 3 01-17-2015 10:00 PM
what this bash script does and what the root cause for the failure Millar Linux - Software 1 03-11-2014 01:30 PM
[SOLVED] 14.0RC2 vs. 13.37: strange Bash script failure kikinovak Slackware 4 08-23-2012 03:09 AM
[SOLVED] bash script failure in Mint 9 Isadora seannachie Linux - Newbie 5 10-30-2011 11:43 AM
[SOLVED] Elementary Bash Scripting Question Eternal_Newbie Slackware 2 08-25-2005 06:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration