You are not logged in.
Pages: 1
Hello,
I think it's just a simple issue, but I don't know much about BASH scripts, normaly I develop in C/C++ but I don't like these Makefiles (don't blame me!!).
Here's my simple code:
#!/bin/bash
#### ####
# INFINITY BUILD SYSTEM #
#### ####
# Project defines
export AVR_CPPFLAGS='-O3 -mmcu=atmega32u4 -I./inc/'
export AVR_LDFLAGS=''
export PROJECT_SOURCES=''
export PROJECT_HOME=.
#########
# Internal defines
export AVR_CPP='avr-c++'
export AVR_LD='avr-ld'
export AVR_OBJCOPY=avr-objcpy
export PROJECT_SRC_DIR=${PROJECT_HOME}/src/
export PROJECT_INC_DIR=${PROJECT_HOME}/inc/
function compile {
for i in $PROJECT_SOURCES do
$AVR_CPP $AVR_CPPFLAGS $to_compile -o ${to_compile}.o
if [ $? -eq 0 ] then
echo “$to_compile:Compiled successfully”
else
echo “$to_compile: FAILED, see log above!”
exit
fi
done
}
it says:
./build.sh: line 29: syntax error near unexpected token `avr-cpp'
./build.sh: line 29: ` avr-cpp $AVR_CPPFLAGS $to_compile -o ${to_compile}.o'
Any help would be nice! Thanks!
Offline
You're missting a semicolon or newline before the 'do' on line 28.
EDIT: and what is "$to_compile"? It is never defined. I think you mean "$i".
Last edited by Trilby (2014-05-29 12:58:19)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
It needs a semi-colon before the 'do' (or drop the 'do' to the next line)
Either one or the other:
for i in whatever; do
stuff
done
for i in whatever
do
stuff
done
You'll have the same error with the 'if' statement too... it will need a semi-colon before the 'then'
if [ $? -eq 0 ]; then
Offline
Also, while not an error, it would be better to use the bash builtin [[ ]] rather than the binary [ particularly since you are envoking bash explicitly.
Last edited by Trilby (2014-05-29 12:59:46)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
EDIT: and what is "$to_compile"? It is never defined. I think you mean "$i".
On a similar point, a couple of nice options for bash scripts are:
set -u
set -e
The first one will stop the script if there are unbound variables and the second will stop on an error. Both can be very useful
#!/usr/bin/env bash
set -e
set -u
# rest of your script etc
Offline
Trilby wrote:EDIT: and what is "$to_compile"? It is never defined. I think you mean "$i".
On a similar point, a couple of nice options for bash scripts are:
set -u
set -eThe first one will stop the script if there are unbound variables and the second will stop on an error. Both can be very useful
#!/usr/bin/env bash set -e set -u # rest of your script etc
Sorry, this is crap advice. set -e has surprising and inconsistent behavior. set -u causes you to code around problems that it creates. The combination of the two flags is a nightmare. There's nothing "similar" about your suggestion and what the OP asked, or what Trilby responded with.
Last edited by falconindy (2014-05-29 15:40:37)
Offline
Sorry, this is crap advice. set -e has surprising and inconsistent behavior. set -u causes you to code around problems that it creates. The combination of the two flags is a nightmare. There's nothing "similar" about your suggestion and what the OP asked, or what Trilby responded with.
From the link you posted:
rking's personal recommendation is to go ahead and use set -e, but beware of possible gotchas. It has useful semantics, so to exclude it from the toolbox is to give into FUD.
The reason I mentioned set -u is because it would have been extremely clear why the first line in the loop gave odd results rather than fundamentally changing what OP thought it was doing. Therefore the similarity was that Trilby mentioned an unbound variable and I posted a method to check for that (however flawed and basic it might be in complex examples)
In saying this, in reading through the programming subforum I certainly appreciate that your programming skills far exceed mine so I'll certainly take your advice/concern on-board
Last edited by oliver (2014-05-29 17:39:13)
Offline
Great guys! Thanks for all the help!
The script can be found at github here:
http://github.com/xvzf/Infinity under the name "ibs.sh"
Again, thank for your help, I've never done anything in BASH before... Now I really like it, i have to say
Offline
xvzy, you may want to peruse Greg's wiki - it is a great reference and learning aid for bash.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Pages: 1