csh code to ksh code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting csh code to ksh code
# 1  
Old 06-16-2010
csh code to ksh code

I have this code using csh and want to convert it to ksh to include this thinking into my ksh scripts.
Code:
     while ( $iarg < $narg )
    MATH iarg = $iarg + 1
    set arg = $argv[$iarg]
    set opt=` echo $arg | awk 'BEGIN { FS="=" } { print $1 }' `
    set par=` echo $arg | awk 'BEGIN { FS="=" } { print $2 }' `
    switch ($opt)
        case "data":
            set Data=$par
            echo "-Rrms " $Data
            set optdata=1
            breaksw
        case "-Rrms":
            set Rrms=$par
            echo "-Rrms " $Rrms
            set optrms=1
            breaksw
        case "-Rbst":
            set Rbst = $par
            echo "-Rbst " $Rbst
            set optbst=1
            breaksw
        default:
            echo "Unrecognised Option"
            set ierr=1
            breaksw
     endsw
  end

# 2  
Old 06-16-2010
Hi.

Some automated conversion may be done with:
Code:
# cshtobash - convert csh aliases, environment variables, and variables to
#	      bash equivalents

http://sysinf0.klabs.be/usr/doc/bash/examples/misc/cshtobash.gz?dist=;arch=

A perl code that claims to do the conversion can be found at:
http://www.linux-kheops.com/doc/perl.../csh2sh-rca.pl

But you will probably need to do some manual work as well. See the first few columns of Rosetta Stone for Scripting Languages ... cheers, drl

Last edited by drl; 06-16-2010 at 11:19 AM..
This User Gave Thanks to drl For This Post:
# 3  
Old 06-16-2010
Code:
while [ $iarg -lt $narg ]
do
  iarg=$(( $iarg + 1 ))
  arg=$argv[$iarg]

  opt=${arg%%=*}
  par=${arg#*=} ## if there's more than one '=', this is a little more complex

  case $opt in
     "data")
         Data=$par
         echo "-Rrms $Data"
         optdata=1
         ;;
   "-Rrms")
        Rrms=$par
        echo "-Rrms $Rrms"
        optrms=1
        ;;
    "-Rbst")
        Rbst = $par
        echo "-Rbst " $Rbst
        optbst=1
        ;;
      *)
        echo "Unrecognised Option"
        ierr=1
        ;;
  esac
done

If I knew a little more about the script, I'd probably recommend using getopts to parse command-line options.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh code explanation

Hi. Can somebody please explain the following lines of KSH code for me? The code checks all sub directories in a specific location which are numbered (E.g. test_01, test_02 ... etc.), then finds the one with highest number and extracts that number from the dir name into the variable num. I'd just... (9 Replies)
Discussion started by: user052009
9 Replies

2. Shell Programming and Scripting

Translate csh to ksh

Hi! I need to translate those line in csh (to initialise variable) into ksh construct. Any help would be appreciated! I don't know how to replace them :( Thanks Hulu setenv TestHul "$0 $*" setenv JG `setenvp "JG" "" "$*"` setenv A_1 `setenvp "A_1" "NA" "$*"` Please use next time... (2 Replies)
Discussion started by: patator67
2 Replies

3. Shell Programming and Scripting

translate ksh code to csh code

hi all, Can any 1 help me translate this korn shell code to C shell code : email=$(grep "^$1" $folder/config_2.txt | awk '{print $2'}) In config_2.txt the content is : which mean in korn shell , $1=groupname and $2=email address. Now i need to write in C shell script,when i set the... (2 Replies)
Discussion started by: proghack
2 Replies

4. UNIX for Advanced & Expert Users

KSH denial error code?

Hi All, I am trying to access ISQL via shell script(SSH). It was working fine (the script had permissions to access for ISQL). Occasionally I am getting the denial message. May I know what is the issue? D FILE abcd Exec 69 2 /sybase/OCS-12_5/bin/isql /usr/bin/ksh What... (0 Replies)
Discussion started by: sharif
0 Replies

5. Shell Programming and Scripting

csh has function -x as ksh ?

Dear All, Normally, I use ksh to code script but I got a new assignment to check the error code of csh so I want to know csh has fuction -x(/bin/ksh -x) as ksh or not? If csh has, which mode? Another way, how can I check it my code is correctly? Thank in advance (2 Replies)
Discussion started by: unitipon
2 Replies

6. Shell Programming and Scripting

python code...convert to ksh or sh

Helloo... I am not much familiar with python..I found this small script in python I even do not have python on my computer...can anyone help me out to convert this into ksh or sh.. PLEASE any help I will appreciate.. here is python code.. #!/usr/bin/env python import random # Get a... (3 Replies)
Discussion started by: amon
3 Replies

7. UNIX for Dummies Questions & Answers

Csh Vs Ksh

I created a simple script and attempted to run it. All that the scrip contained was "ls -l". At first I received the message "ksh: run_dir: not found" I then tried typing "csh run_dir" This time the script worked. typing echo $SHELL produced /bin/ksh I would like to understand why this... (4 Replies)
Discussion started by: SUSANR9999
4 Replies

8. Shell Programming and Scripting

\!* in csh what is it for ksh

Hey guys, Hopefully a simple question for you. In csh I have an alias that looks like: alias ff 'find . -name \!* -print' and can therefore perform a search for a file by typing: ff filename The same comand does not work in ksh alias ff="find . -name \!* -print" I get: find:... (3 Replies)
Discussion started by: timsk
3 Replies

9. UNIX for Dummies Questions & Answers

switch from csh to ksh

My UNIX SA requires that we start in CSH. I like to use KSH because most of my experience is in that shell. I added ksh to the end of my .login script which does take me into KSH but I would like to automatically execute my .profile to setup my aliases. I cannot use a .shell file because I... (1 Reply)
Discussion started by: veeracer
1 Replies

10. Programming

Exit Code in HP-UX KSH.

In one of my programs another process is called using the system command e.g. lv_error = system("myproc"); where lv_error is declared as an int. myproc would be returning 0 for success and 1 for failure. e.g. if (success) { return(0); }else{ return(1); } When the return code... (3 Replies)
Discussion started by: mbb
3 Replies
Login or Register to Ask a Question