Skip to content
Advertisement

csh scripting for password authorisation of user

I’m trying to write a professional program to accept and process input via a Menu based system. The program should have no command line arguments. it will be writen in csh script called TaskMenu. This shell script will:

  1. ask for a password from the user.
    a. If the password is not correct, the system will exit with an appropriate error message.
  2. display a text menu and then get a response from the user.
  3. process the user input and redisplay the text menu until the user wants to quit.

Advertisement

Answer

To read a password, turn echo off, read the password, then re-enable echo. csh:

JavaScript

To create a menu, just echo the choices to the screen, then read a value back. csh:

JavaScript

These same two tasks in bash are:

Read password:

JavaScript

Make menu:

JavaScript

Notice how reading a password and making a menu are built-in to bash. In addition to being easier, some common things done in scripting are impossible in csh. Csh is not designed as a scripting language. It is much easier to use Bash, Python, Ruby, Perl or even the lowly /bin/sh for scripting anything over a few lines.

That said, here is a full csh script showing the password and menu methods:

JavaScript

Notes

Though popular for interactive use because of its many innovative features, csh has never been as popular for scripting[1]

1 Wikipedia

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement