BASH Scripting Troubles with IF and FUNCTION
Hey guys, im running macosx 10.4.4 which of course uses linux under neath and ive been trying to write up a script for both my mac and linux box, but at the momment it seems the script hits a halt during the archive bit
Code:
#! /bin/bash |
Quote:
|
well its not exactly linux but much in the terminal is near the same cmds as a linux machine, anywho the fact is this is about bash scripting which both have, so can someone help me and tell me if anything is wrong with it
|
I don't know how it is on your box but, on my FC4 machine, the if statement doesn't work when the [ brackets ] are too close to the [number].
Code:
#!/bin/bash |
well i fixed up all the brackets but still after the archive is made it just skips right to the end of the script
|
also is there a way to make it link to another file, so like in c++ u could have another file with ur functions in it is this possible in bash
|
Read the man pages. I suppose there is a possibility to include other files (like the #include in C).
For instance, in the /etc/init.d/* scripts, often written in Bash, the script /etc/init.d/functions is usually "included" by: . ./etc/init.d/functions Also, you should pay attention to programming syntax. Several shells have different if-syntax for numeric comparisons (called "ARITHMETIC EVALUATION") and for string/other comparisons. So, if your variable stores a number, you should use the number syntax, not the string syntax, etc. If you want to test if a number equals 1 in Bash, I think it's supposed to be written as: if (( $num == 1 )); then do_some_code; fi; But, to test if a file exists, you need to use: if [[ -f $file_name ]]; then do_some_code; fi; In short, read "man bash", like the rest of us - lol |
Bad Interpreter
Hey guys, this one is a new question but ill stay in one thread, im trying to build a few scripts for my suse 10 box but when ever i try to run the script i get this
bender:/home/gserver # ./utilities.sh : bad interpreter: No such file or directory Code:
#!/bin/bash |
Basically, #!/bin/bash tells your system that it should use the bash shell (the program /bin/bash) to interprete the code below that line.
In other words, your script uses the Bash shell syntax. However the error "bad interpreter" suggests that you don't have the /bin/bash program. Try doing ls -l /bin/bash whereis bash If they don't tell you that you have bash, you probably don't have it. /bin/sh is similar, but somewhat older and thus may lack some features of Bash. Try changing #!/bin/bash into #!/bin/sh and run the script again to see if it works. Otherwise, echo $SHELL to print the shell you're currently using. You could try re-writing your script using that shell (and it's specific syntax) as well. |
EDIT: ok my mistake it seems that my windows notepad2 i had been using had placed werid formatting to it even tho its txt, is there any good notepad apps that do the colouring of text for certain functions
PS. i know about vim but thats just all one colour im sure bash is there and working becuase i have other scripts that load and run fine, i copied that direct line from another script that i know works. also here is the out put of the cmd Code:
bender:/home/gserver # ls -l /bin/bash |
On Windows, you could try using a professional editor rather than notepad or wordpad (that won't do syntax highlighting).
Try something like TextPad or UltraEdit. You can try them for free, but have to pay for a license. As for vim, it shouldn't put everything in just one colour. My vim recognizes my scripts and source code just fine and highlights the syntax correctly. If that's not the case for you, I'd recommend you taking a look at your syntax. Maybe you've accidentally commented out everything or disabled syntax highlighting? If you want other editors then vim, try using a graphical one, like gedit, nedit, kedit, etc. Search this forum for others. |
All times are GMT -5. The time now is 10:30 PM. |