Sh script variable checking
Hello all,
I have a Bourne shell script and on occasion I add to my script. I have one variable set to a folder directory and a different variable set to a different directory. My variables are: ORIGINAL0=/home/user ORIGINAL1=/etc/networks/ When I do add my variables I sometimes misspell the variables like: OrIGINAL0 or ORIIGINAL1. This messes with my script and frustrates me. I would like to be able to some how check for these kinds of errors before the script runs. Any help would be appreciated! |
I've always taken syntax errors as part of the coding activity... yes it may be frustrating at the beginning but instead of looking for some automated thing that corrects your code for you, I'd advice you to get over the feeling and just improve on your attention while coding. With time you'll commit less and less errors.
Should such a tool exist, you still will face debugging and improve your discipline while coding. I don't really think there are other ways. |
AFAIK, there's no pre-flight syntax checker for shell, and there's no way it could know what you want your vars called...
what is very useful for debugging is adding this as the next line after the shebang line Code:
set -xv The other tip is to write small sections of code & then test them individually (eg using that cmd), don't try to write an entire script in one go. |
Thank you for the replies. I did manage to find the following:http://www.grymoire.com/Unix/Sh.html#uh-31 I think that I will try what it suggests and see what happens.
|
If you include this early in your script, bash will generate an error if it references an unset variable
Code:
set -o nounset |
All times are GMT -5. The time now is 09:26 PM. |