C Shell Scripting on SUA windows 7


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting C Shell Scripting on SUA windows 7
# 1  
Old 10-12-2012
Network C Shell Scripting on SUA windows 7

hi,

Even $eType is BSD_8GB
Code:
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....

Last edited by fpmurphy; 10-13-2012 at 10:48 PM.. Reason: code tags please!
# 2  
Old 10-12-2012
Hi.

Placing your code into a script:
Code:
#!/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:
Code:
% ./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
# 3  
Old 10-12-2012
value of $eType pased from the other file using grep.Smilie,In normal case work fine.
# 4  
Old 10-12-2012
Hi.
Quote:
Originally Posted by gthangav
value of $eType pased from the other file using grep.Smilie,In normal case work fine.
How is it "pased" ? -- show us the code ... cheers, drl
# 5  
Old 10-15-2012
Network

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

O/p-> BSD_8GB
# 6  
Old 10-15-2012
Hi.

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

Please post the smallest part of the file s.cfthat 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:
Code:
#!/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:
Code:
% ./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:
Code:
dos2unix (1)         - DOS/Mac to Unix and vice versa text file format converter

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Need Help in Windows scripting

Dear Expert, Below code is for to take the backup of database by daily time stamp. I need vital help to make my script automatic sending me email if it sucess or fail. Code: echo on @REM Seamonkey’s quick date batch (MMDDYYYY format) @REM Setups %date variable @REM First parses... (0 Replies)
Discussion started by: Alone
0 Replies

2. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

3. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

4. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

5. Shell Programming and Scripting

Shell scripting on Windows platform

Is there a free unix platform that will allow me to write a shell script on my Windows OS? I have my files on my C: drive and i need to write a script that reads from those files and does some manipulation. Its pretty straightforward in unix commands hence i don't want to write a Java/C++ program... (3 Replies)
Discussion started by: jakSun8
3 Replies

6. UNIX for Dummies Questions & Answers

Need help configuring Active Perl on Windows Vista.: Perl Scripting on Windows

Hi All, Need help configuring Active Perl on Windows Vista. I am trying to install Active Perl on Windows Vista. The version of Active Perl i am trying to install is : ActivePerl 5.10.1 Build 1006 After installing it through cmd, When i try to run perl -v to check the version, i get the... (2 Replies)
Discussion started by: Vabiosis
2 Replies

7. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

8. Windows & DOS: Issues & Discussions

Windows Scripting

I have been involved with shell programming now for the last 5 or 6 years. I am directing my career towards IT Security and need to broaden my experience. I would like suggestions for a good programming language for Windows. Is there a Windows scripting language that is considered secure ? Has... (3 Replies)
Discussion started by: sunsysadm2003
3 Replies

9. Windows & DOS: Issues & Discussions

windows scripting for a batch job

I have been doing unix scripting for quite awhile and there seems to be a wealth of information on it. Now I am working on migrating an intel based application to a new server. I need to modify some existing scripts, but am having trouble finding information on windows scripting, a forum similar... (2 Replies)
Discussion started by: MizzGail
2 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question