Help with Check Syntax of Shell Script without Running


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Check Syntax of Shell Script without Running
# 1  
Old 08-24-2014
Help with Check Syntax of Shell Script without Running

Hi Everyone,

Is there any way ( generic) to check syntax of Shell Scripts without running it??
# 2  
Old 08-24-2014
Assuming you're using a shell based on Bourne shell syntax (such as ksh or bash), try:
Code:
YourShell -n YourScriptPath

# 3  
Old 08-24-2014
Don's suggestion is the best bet. You can also try adding a line like this at the top
Code:
set -n

in the script itself. For modern shells - NOT csh.
# 4  
Old 08-25-2014
Thanks for the help... I tried sh -n <script-name> it worked fine for some errors...

But in case of the following errors, nothing happened
Example:-


1)

export FILE1=INPUT-FILE
export FILE2=OUT-FILE
cp FILE1 $FILE2


Here $ should be there before FILE1.
This error is not caught

2) If a file which is declared, is not at all present in the path mentioned, those errors are not handled

3) # is not present in the starting of comment line...this error is not being caught.

Is there any way to take care of the above??
# 5  
Old 08-25-2014
In the thread title you talk about syntax errors and those are checked with the -n flag.
Your examples 1) and 2) are semantic errors but syntactically correct.
1) copying a file called FILE1 is syntactially valid, no matter wheter you have defined a variable with the same name or not.
2) what do you mean when you say "a file which is declared"? Anyway, a file can be created any time. It is no syntax error just because a file referenced any way is not there at the time you check the syntax.
3) may be a special case of 2). The comment may be interpreted as an executeable with arguments (which does not have to exist at the time you check).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check status of long running multiple curl commands in shell script

I am working on script. it reads a file which contains multiple lines Ex; curl --write-out %{http_code} --silent --output /dev/null http://hostname:port/input=1 curl --write-out %{http_code} --silent --output /dev/null http://hostname:port/input=2 curl --write-out %{http_code} --silent ... (2 Replies)
Discussion started by: oraclermanpt
2 Replies

2. Shell Programming and Scripting

Shell script check syntax not working ...

Hello i have question that i want check syntax from my script shell with sh -n filename but it's not show something even i have wrong syntax in my file. why can this happened or any other way to check it? i use on header of file : #!/bin/sh thx before :) (7 Replies)
Discussion started by: Gochengz
7 Replies

3. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

4. Shell Programming and Scripting

CHECK SCRIPT SYNTAX

Hi everyone, i'd like someone chechk this script, i know it's very simple but it doesn't work good, let me tell you this script works over huge directories, maybe that's the problem, if somebody can give me other way to develop, or show me where it's the problem, i'll appreciate it. ... (9 Replies)
Discussion started by: Newer
9 Replies

5. Solaris

How to check if a shell is already running ?

Hi, I put this at start of my shell (korn shell) to be sure that the shell is not already running and sometimes it fails and says that it is already running which is not true ! sleep 1 /usr/bin/ps -ef | /usr/bin/grep "$0" | /usr/bin/egrep -v grep>$LOGDIR/$0.res isup=$(cat $LOGDIR/$0.res|wc... (4 Replies)
Discussion started by: zionassedo
4 Replies

6. Shell Programming and Scripting

script to check if another script is running and if so, then sleep for sometime and check again

Hi, I am a unix newbie. I need to write a script to check wheteher another script is still running. If it is, then sleep for 30m and then check again if the script is running. If the script has stopped running then, I need to come out of the loop. I am using RHEL 5.2 (2 Replies)
Discussion started by: mathews
2 Replies

7. Shell Programming and Scripting

K script not running / syntax problem

Hi, I have following K script, that is in rc0.d directory to be run on shutdown. It's linked using the 'ln' command to init.d.Can anyone tell me as to why it's not running, or if i have incorrect syntax?I get: "test: argument expected type=uname -p + " When running it with sh -x ... (8 Replies)
Discussion started by: darrlaw
8 Replies

8. Shell Programming and Scripting

How to Check Shell script syntax w/o executing

Hello All, I looking for a way to verify the correction of shell script syntax. Is there any switch like -c in perl which do this in shell ? Thank You. (1 Reply)
Discussion started by: Alalush
1 Replies

9. UNIX for Advanced & Expert Users

how to check if a process is running in a server from shell script.

I want to write a unix shell script that will check if a process (say debu) is running in the server or not. If no , then send a mail to the corresponding person to start the process??? (2 Replies)
Discussion started by: debu
2 Replies

10. UNIX for Dummies Questions & Answers

check my code?? running shell from c?

Hi mates, i am trying to run a shell command from my C program in this case let is say the "ls" command. It copiles it okay, and even creates the new fork too. But seems to nothing is happening i mean it is not showing the result of the "ls" command. I don't know wat i am doing wrong. Any... (1 Reply)
Discussion started by: abdul
1 Replies
Login or Register to Ask a Question