Validation of linux scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Validation of linux scripts
# 1  
Old 05-31-2012
Question Validation of linux scripts

Hi,

I have a script which invokes another script inside. Is there any way I can validate the script for syntax errors as well as checking if the files mentioned in the commands exist without executing it? Below is an example

Example.

=======================
Script1

#ksh

echo "Start of script"

. script2

echo 'end of script'


=====================
Script2

echo "control in script2"
cp fileold filenew
cat filenew >> filect
cp filect
echo "end of script2"
=====================
# 2  
Old 05-31-2012
There is no full-coverage syntax checker for ksh. The closest is probably shcomp which builds and saves the internal parser tree if no errors are encountered.
# 3  
Old 06-01-2012
Thank you very much. Please let me know if it can be possible in any other shells..
# 4  
Old 06-01-2012
Successively applying
Code:
[ -f <FileName> ]

option of the test command will test whether the files in question exist or not.

In your case
fileold must not exist,
filenew should not exist and so on.

You might then change script2 to something like:
Script2

Code:
echo "control in script2"
if [-f filenew ] then
echo filenew already exist.
exit
fi
cp fileold filenew
cat filenew >> filect
cp filect
echo "end of script2"

=====================
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux xmllint schema validation fails but error code 0

Command line xmllint --schema validation fails but $? returns 0 myinput.xml: <myinput><header>mytestvalue</header></myinput>myschema.xsd <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="myinput" type="xsd:string"/> </xsd:schema>Command: $xmllint --schema... (4 Replies)
Discussion started by: mknag
4 Replies

2. Shell Programming and Scripting

Can anybody change this into Linux shell scripts?

@echo off SET "p0=%~0" SET "p1=%~1" SET "p2=%~2" SET "p3=%~3" SET "p4=%~4" SET "p5=%~5" SET "p6=%~6" SET "p7=%~7" SET "p8=%~8" SET "p9=%~9" SHIFT SET "p10=%~9" SHIFT SET "p11=%~9" SET "zip_path=D:\OraOutput\interco\%p10%" echo Program... (5 Replies)
Discussion started by: monisha
5 Replies

3. Shell Programming and Scripting

Linux - scripts not working in cron

hi all, i have scripts executable in manully, but not working in cron. any ideas? thanks a lot? * * * * * /home/dir/dir/file.sh #! /bin/sh alarmPath="/home/dir/monitoringAlarm" alarmDateTime="$(date +%Y%m%d) $(date +%H%M%S)" tomcatPID=`pidof /usr/local/jdk1.6.0_13/bin/java` echo "tomcat... (3 Replies)
Discussion started by: maxlee24
3 Replies

4. Red Hat

Linux - scripts not working in cron

hi all, i have scripts executable in manully, but not working in cron. any ideas? thanks a lot? * * * * * /home/dir/dir/file.sh #! /bin/sh alarmPath="/home/dir/monitoringAlarm" alarmDateTime="$(date +%Y%m%d) $(date +%H%M%S)" tomcatPID=`pidof /usr/local/jdk1.6.0_13/bin/java` echo "tomcat... (1 Reply)
Discussion started by: maxlee24
1 Replies

5. Shell Programming and Scripting

shell scripts for linux SLES 10

Hi, could someone help me to create the following scripts Need to create couple of shell scripts on LINUX SLES 10 Using my id --------------- First script – this script should contain su and should take input <process name> 1 -login using my id and then sudo to... (1 Reply)
Discussion started by: lookinginfo
1 Replies

6. Shell Programming and Scripting

perl linux file name validation

Hi Everyone, #!/usr/bin/perl $a = ".a!"; if ($a =~ s///g) { print "invalid file name\n"; } else { print "valid file name\n"; } but the output is: Invalid range "_-." in regex; marked by <-- HERE in m// at ./a.pl line 5. the linux file name should be A-Z, a-z,... (8 Replies)
Discussion started by: jimmy_y
8 Replies

7. UNIX for Dummies Questions & Answers

Unix/Linux Scripts questions

Hi All, You have a very large file, named 'ColCheckMe', tab-delimited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values in the 5th column are integers. Using shell functions (and standard LINUX/UNIX filters), indicate how you would... (7 Replies)
Discussion started by: am2007
7 Replies

8. UNIX for Dummies Questions & Answers

pulling scripts from unix to linux

:confused: I am working on transferring "good" running code scripts from unix to linux (suse). Some errors show in linux that are not present in unix. Specifically, the error code is: codename : no closing quote This is referring to the last line of the code + one line. I have used temporary... (3 Replies)
Discussion started by: pjconfig
3 Replies

9. UNIX for Dummies Questions & Answers

Linux Scripts

I'm pretty new to the world of linux, so no flames please. I know there is a plethora of info out on the internet about writing scripts for linux, but few give actual examples. I need some help with learning the basics of writing some simple scripts to learn the difference between windows and... (1 Reply)
Discussion started by: Strm2k
1 Replies

10. Shell Programming and Scripting

scripts in another linux m/c via ssh

I want to write a script which connects to another linux via ssh. now i need to execute the rest of my script in that linux.. the echo is coming only when i exited from 10.1.1.252.. pls help (4 Replies)
Discussion started by: esham
4 Replies
Login or Register to Ask a Question