Flow Control in CSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Flow Control in CSH
# 1  
Old 08-10-2011
Flow Control in CSH

hi ,
I am new to scripting, i have a doubt can any one pls solve it for me
the code is not working

Code:
set users = (user1 user2 user3)

echo The users are
echo $users[*]
echo Enter the USER NAME 
set USER_NAME = $<
set i = 1;
for ( i = 1; i <= $#users; i++ )
if ( $USER_NAME == $users[i] ) then
mkdir root/project/$USER_NAME
else echo INVALID USER!!!!
endif
done


this is not working... how do i check whether the users are valid or not... and ask again to enter the users if the input is invalid...

Last edited by pludi; 08-10-2011 at 04:54 AM..
# 2  
Old 08-30-2011
You are mixing syntax of csh with sh/bash elements.
Exclamation marks in strings need to be escaped because of their special meaning in csh.
Code:
#!/bin/csh
set users = (user1 user2 user3)
echo The users are
echo $users[*]
set found = 0
while ( $found == 0 )
  echo Enter the USER NAME 
  set USER_NAME = $<
  foreach user ($users)
    if ( $USER_NAME == $user ) then
      echo mkdir root/project/$USER_NAME
      set found = 1
      break
    endif
  end
  if ( $found == 0 ) then
    echo "INVALID USER: $USER_NAME \!\!\!"
  endif
end

But possibly it is a better idea to learn ksh/bsh/bash scripting.
csh and tcsh are good for interactive working, but not so much for scripting.
Have a look at Advanced Bash-Scripting Guide
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Flow control state changed in server logs

Hi, We observe below logs from switch - the database servers rebooted becaause they couldn't do I/O on vfiler -Any pointers looking at below logs please? Switch logs: 2016 Apr 30 07:41:16.729 EAG-ECOM-POD111GPU-SWF1 %ETHPORT-5-IF_DOWN_LINK_FAILURE: Interface Ethernet152/1/8 is down (Link... (0 Replies)
Discussion started by: admin_db
0 Replies

2. Shell Programming and Scripting

Help with control flow in a Bash script

In my bash script I want to say "if argument 2 is anything except x, y or z, than echo this" (x y and z being words). So my script looks like this: if ] then echo "unrecognized input: $2" fi This usually works but than I also want to say "if argument 2 IS x, y, or z, but argument 4 is... (4 Replies)
Discussion started by: Jrodicon
4 Replies

3. Shell Programming and Scripting

Will this flow work

B() { } A() { calling a function B } for condition do calling a function A done Shall after executing function B, the control will return back to loop? Thanks in advance :) (2 Replies)
Discussion started by: ezee
2 Replies

4. Shell Programming and Scripting

Backup script using Korn Flow Control

I am wiping off the dust to my shell scipting days and had this question: I have this script that I have created, and cannot figure out where my flow control issue is within this script. #!/bin/ksh #Basic script to backup server #Home directories to the external ... (2 Replies)
Discussion started by: metallica1973
2 Replies

5. Shell Programming and Scripting

Python script - control flow statements

Hi guys.I'm just beginner of python. I'm just trying to do some analysis on simple input file. it has 6 columns and i want to consider k,l and m,n if i and j are + after that checking which value is greater or lower in k,l and m,n I have included logic header just to explain what I was... (4 Replies)
Discussion started by: repinementer
4 Replies

6. UNIX for Dummies Questions & Answers

For loop control with two variables in csh shell

Hi All How can i control for loop with two different variables in csh shell Regards Nikhil (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies

7. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

8. IP Networking

Disabling 802.3x flow control

I have a server I would like to disable 802.3x flow control on. The host is Linux (CentOS 4.4 x86_64 w/ 2.6.9-42.0.3.EL kernel,) and I'm using the ns83820 driver for the ethernet interface in question. I've tried looking at the driver parameters (modinfo ns83820) and using ethtool (ethtool -a... (0 Replies)
Discussion started by: LivinFree
0 Replies

9. Programming

dilemma in control flow

hello im facing a queer problem when i execute the foll code in unix # include <stdio.h> # include <unistd.h> main(int argc,char *argv) { FILE *fp = fopen("/ras/chirag/fifotest/file.fifo","a"); int i=1; fprintf(fp,argv); printf("I SLEEP"); system("date"); for (i=0;i<50;i++)... (2 Replies)
Discussion started by: tej.buch
2 Replies

10. UNIX for Dummies Questions & Answers

how to assign correct control flow?

how can i create a script with a correct control flow/loop(?) to provide output from 3 files? file1 one two three file2 yellow red orange file3 banana apples cantaloupes output file: one (1 Reply)
Discussion started by: apalex
1 Replies
Login or Register to Ask a Question