Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-16-2011, 09:31 AM   #1
Registered: Jan 2010
Distribution: Ubuntu
Posts: 97

Rep: Reputation: 4
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:

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!
Old 11-16-2011, 10:39 AM   #2
Registered: Mar 2010
Posts: 202

Rep: Reputation: 84
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.
Old 11-16-2011, 06:29 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,559

Rep: Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424Reputation: 2424
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
set -xv
This shows the 'before & after' versions of each line as it is processed; very informative.
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.

Last edited by chrism01; 11-17-2011 at 06:21 PM.
Old 11-17-2011, 09:09 AM   #4
Registered: Jan 2010
Distribution: Ubuntu
Posts: 97

Original Poster
Rep: Reputation: 4
Thank you for the replies. I did manage to find the following: I think that I will try what it suggests and see what happens.
Old 11-17-2011, 12:27 PM   #5
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
If you include this early in your script, bash will generate an error if it references an unset variable
set -o nounset
1 members found this post helpful.


bourne, script, scripting

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
[SOLVED] Shell Script is showing error after whenever checking a special variable emcykm Linux - Newbie 5 06-01-2011 10:59 AM
[SOLVED] Checking variable against multiple values ksushants Linux - Newbie 6 03-02-2011 10:27 AM
[SOLVED] Checking the existence of env variable mahmoodn Linux - General 8 06-12-2010 10:51 AM
Checking variable is numeric ijf99 Programming 2 03-28-2009 09:13 AM
Checking whether a variable is alphabetic basildon Linux - Newbie 4 09-21-2008 05:03 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:56 PM.

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