Problems with ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems with ksh
# 1  
Old 11-11-2010
Problems with ksh

I have the following ksh code and I am passing

f="npt06-sr40-syn-dc0p02-32x24drw.mis"

For some reason, it's going to the else statement instead of setting
optfdrw=1


Code:
    smptag=$(print -R $f | awk '/smp/')
    drwtag=$(print -R $f | awk '/drw/')
    if [ $drwtag != "" ] && [ $smptag == "" ] ; then   # drw tag detected
        optfdrw=1
    elif [ $drwtag == "" ] && [ $smptag != "" ] ; then  # smp tag detected
        optfsmp=1
    else
        echo ""
        echo "ERROR: $f"
        echo "       Log file name has no 'smp' or 'drw' tag"
        echo "$optfdrw $optfsmp"
        exit 1
    fi

# 2  
Old 11-11-2010
use [[ ... ]] instead of [ ... ] :

Code:
if [[ ... ]] && [[ ... ]]

instead of
Code:
if [ ... ] && [ ... ]

Code:
elif [[ ... ]] && [[ ... ]]

instead of
Code:
elif [ ... ] && [ ... ]


Last edited by ctsgnb; 11-11-2010 at 09:36 PM..
# 3  
Old 11-11-2010
MySQL Problems with ksh

Code:
#!/bin/ksh
    f="npt06-sr40-syn-dc0p02-32x24drw.mis"
    smptag=$(print -R $f | awk '/smp/')
    drwtag=$(print -R $f | awk '/drw/')
    if [ "$drwtag" != "" ] && [ "$smptag" == "" ] ; then   # drw tag detected
        optfdrw=1
    elif [ "$drwtag" == "" ] && [ "$smptag" != "" ] ; then  # smp tag detected
        optfsmp=1
    else
        echo ""
        echo "ERROR: $f"
        echo "       Log file name has no 'smp' or 'drw' tag"
        echo "$optfdrw $optfsmp"
        exit 1
    fi

enclose the variables $drwtag and $smptag with double quotes " " inside the if and elif statements,
that will get it to work...Smilie
# 4  
Old 11-11-2010
Using -n and -z works.

What would be safest to use? -n and -z or [[ ]] ?

Code:
    if [ -n $drwtag ] && [ -z $smptag ] ; then   # drw tag detected
        optfdrw=1
        echo "drw"
    elif [ -z $drwtag ] && [ -n $smptag ] ; then  # smp tag detected
        optfsmp=1
        echo "smp"
    else
        echo ""
        echo "ERROR: $f"
        echo "       Log file name has no 'smp' or 'drw' tag"
        echo "$optfdrw $optfsmp"
        exit 1
    fi

# 5  
Old 11-11-2010
yes , double quote $var or double square bracket or -z & -n ...
orange & apples Smilie
# 6  
Old 11-11-2010
As for the double square brackets

Should the below work for example?

if [ $optfstmod -eq 1 ] && [ $optfrestore -eq 1 ] ; then

[ $optfstmod -eq 1 ] is a test statement that will work in any bourne type shell and is POSIX compliant. [[ $optfstmod -eq 1 ]] is a conditional expression that is specific to ksh and bash and offers more possibilities and is a bit faster, but it is not POSIX compliant and as as such will likely not work in other Bourne type shells.

What do you think?
# 7  
Old 11-11-2010
Don't use ksh then ... just use the POSIX sh ! Smilie

If you don't want to use new things because may not be compliant with old one, then just stick with old one Smilie

No, seriously, if you are achiving script that are intended to perform tasks with high compliance constraints for migration , or because used on a very heterogeneous environment or whatever, of course you'd better stick with things that are the most portative possible.
Otherwise, i would go for taking advantage of the functionnalities offered by the shell you are using.
By the way, i think that ksh is already very portative.

The most important is to have a code
1. resource friendly
2. easy to read/maintain so you should comment what you do so someone else can read it easily

Last edited by ctsgnb; 11-11-2010 at 10:12 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

problems with ksh array and find command

set -A allfiles `find $usrhtml -type f` i am trying to populate this array with the find command. It works fine when find is looking through a single directory but when i add a new subdirectory the files in the subdirectory get duplicated. Can anyone help me and fix this so each files in... (1 Reply)
Discussion started by: bjhum33
1 Replies

2. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

3. Solaris

Problems Running KSH on Solaris 10

Hi, I am currently in the process of testing upgrading from Solaris 8 to Solaris 10. one problem i have encountered is when i am running any of my batch scripts. All my scripts start with #! /bin/ksh so that they will excuted in the ksh shell. but the scripts will not run correctly. The... (3 Replies)
Discussion started by: dshakey
3 Replies

4. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

5. Shell Programming and Scripting

autosys/ksh - problems with script

Hi, I'm using autosys and want to set it up that I receive emails when certain jobs start and finish. I don't want to edit each jobs script (ksh) to send a mail at start and finish, I would rather have a single script/job that watches for a trigger when the jobs have started or finished. I... (1 Reply)
Discussion started by: weszardoz
1 Replies

6. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

7. Shell Programming and Scripting

Strange parameter passing problems (KSH)

Hi all, I'm having a rather peculiar problem involving parameter passing with declared functions in my shell script. Hope to get some advice here. A brief description of my code is as follows: However, I'm not getting the results I wanted. If I pass in $rdir, I'm going to end up... (4 Replies)
Discussion started by: rockysfr
4 Replies

8. Shell Programming and Scripting

Problems with Perl/KSH Web Log Script

Hi, I am writing a series of scripts for work to analyse intranet access logs. All of the scripts do as they should when run individually from the shell, but only when run from certain directories. This sounds like it may be a PATH issue but I am not sure. When I run a certain script, say... (3 Replies)
Discussion started by: mmanders
3 Replies

9. UNIX for Advanced & Expert Users

'make' problems (compliation problems?)

I'm trying to compile and install both most recent version of 'make' and the most recent version of 'openssh' on my Sparc20. I've run into the following problems... and I don't know what they mean. Can someone please help me resolve these issues? I'm using the 'make' version that was... (5 Replies)
Discussion started by: xyyz
5 Replies

10. UNIX for Dummies Questions & Answers

having ksh script problems

well i have written a script to telnet and ftp to all my servers, the script runs great, BUT i can not for the life of me figure out how to get the script to repeat if the conditions are not filled. this is what i have so far ######################################### TorF(){ echo T... (4 Replies)
Discussion started by: jerzey4life
4 Replies
Login or Register to Ask a Question