C Shell Scripting on SUA windows 7

hi,

Even $eType is BSD_8GB

echo $eType
switch ( $eType )
    case BSD_8GB:
    case BSD_12GB:
               echo "excuted BSD_8GB & BSD_12GB"     
     breaksw
    default:
        echo "default"       
        exit 0
endsw

Result always default case printing. Please help....

Hi.

Placing your code into a script:

#!/usr/bin/env tcsh

# @(#) s1	Demonstrate switch-case, csh, tcsh.

# Infrastructure details, environment, commands for forum posts. 
# Uncomment setenv command to run script as external user.
# setenv PATH "/usr/local/bin:/usr/bin:/bin"
echo
setenv LC_ALL C ; setenv LANG C
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1 && version '=o' tcsh"
echo

set eType = "BSD_8GB"
echo " eType is $eType"
switch ( $eType )
  case BSD_8GB:
  case BSD_12GB:
    echo " executed BSD_8GB & BSD_12GB"
  breaksw
  default:
    echo "default"
    exit 0
endsw

exit 0

producing:

% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility version)
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
tcsh 6.14.00

 eType is BSD_8GB
 executed BSD_8GB & BSD_12GB

So it seems to work for me.

As usual: if you have the choice, use Bourne-shell family shells for scripting.

Best wishes ... cheers, drl

value of $eType pased from the other file using grep.:wall:,In normal case work fine.

Hi.

How is it "pased" ? -- show us the code ... cheers, drl

set eType = `grep -v "^#" $GP_SUA$GP_ET/s.cf | grep "engineType" | awk -F= '{print $2}'`

O/p-> BSD_8GB

Hi.

I don't have the file $GP_SUA$GP_ET/s.cf

Please post the smallest part of the file s.cf that will cause the script to fail.

I'm guessing that the file may have Windows line terminators: the usual terminology is newline. In *nix the newline is the line feed character, in Windows it is carriage return followed by a line feed.

See The End of Line Puzzle and http://www.rfc-editor.org/EOLstory.txt for details on the end-of-line situation.

Here is an example with a Windows-compatible-stye data file:

#!/usr/bin/env tcsh

# @(#) s2	Demonstrate switch-case, csh, tcsh.

# Infrastructure details, environment, commands for forum posts. 
# Uncomment setenv command to run script as external user.
# setenv PATH "/usr/local/bin:/usr/bin:/bin"
echo
setenv LC_ALL C ; setenv LANG C
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1 && version '=o' tcsh"
echo

set FILE = data1
echo " Contents of input file $FILE"
cat -A $FILE

echo
echo " Results"
set eType = `grep -v "^#" $FILE | grep "engineType" | awk -F= '{print $2}'`
echo " eType is $eType"
switch ( $eType )
  case BSD_8GB:
  case BSD_12GB:
    echo " executed BSD_8GB & BSD_12GB"
  breaksw
  default:
    echo "default"
    exit 0
endsw

exit 0

producing:

% ./s2

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility version)
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
tcsh 6.14.00

 Contents of input file data1
# This line contains the target string.^M$
engineType=BSD_8GB^M$
# Last line in file.^M$

 Results
 eType is BSD_8GB
default

Note the additional ^M strings in the display of the input data file, the extracted string seems to print as normal, but the case fails.

If this is the situation with your data file, then the solution will be to transform your data file with the use of a utility like:

dos2unix (1)         - DOS/Mac to Unix and vice versa text file format converter

Best wishes ... cheers, drl