Showing posts with label C shell. Show all posts
Showing posts with label C shell. Show all posts

Tuesday, November 6, 2012

V7/x86: Adding the current subdirectory to the prompt

The .cshrc script for the C shell in default guest account in V7/x86 is pretty spare. One of the first things I wanted to change after switching over to C shell is the prompt. I'd like the prompt to display the current subdirectory as I navigate the file system.

I want to go from this:

% cd src
%

To something like this:

/usr/guest% cd src
/usr/guest/src% 

The Unix V7 "pwd" command returns the current directory path. We can use this in our .cshrc script to include it's output in the prompt.

% pwd
/usr/guest
%

A great reference that helped me figure this out is the Unix FAQS at http://www.cs.albany.edu/~wuye/unixfaqs.html

Open .cshrc with the "vi" editor and move to the bottom of the file. Add the following text and save.

# add the current directory path to the prompt
alias setprompt 'set prompt="`pwd`% "'
setprompt
alias cd 'chdir \!* && setprompt'

The "alias" command gives us to create a new command that is composed of other commands. We've created the command "setprompt" so that we can use it twice without accidentally changing it between each use.

On the next line we call "setprompt" to display the current path when we login.

On the third line, we create a new alias for the "cd" command that will change the directory and reset the prompt to include the changed directory path.

Editing the .cshrc script
Logout and log back in and you'll see the following:

It works!


Monday, November 5, 2012

V7/x86: Changing the User's Shell

"And in her ears the little Seashells, the thimble radios tamped tight, and an electronic ocean of sound, of music and talk and music and talk coming in, coming in on the shore of her unsleeping mind. The room was indeed empty. Every night the waves came in and bore her off on their great tides of sound, floating her, wide-eyed, toward morning. There had been no night in the last two years that Mildred had not swum that sea, had not gladly gone down in it for the third time." - Fahrenheit 451 by Ray Bradbury
The default shell in Unix V7 is the Bourne shell (sh). It replaced an earlier shell and has itself been replaced by a long line of shells over the years. V7/x86 also includes the C shell (csh).
The computing history has produced a lot of wordplay like this. For example, GNU is a recursive acronym for "GNU's Not Unix!", YACC is Yet Another Compiler Compiler, and GIMP is the GNU Image Manipulation Program. I had once created a PHP based template processor years ago called YATP - Yet Another Template Parser.
The C shell included several improvements over the Bourne shell. The script syntax was more like the C programming language whereas the Bourne took its inspiration from Algol 68. There were improvements in history tracking as well as others, you can read the details in the link above.

The user can drop into another shell from within a shell just by executing the desired shell program. For the C shell, just type in the following command. The prompt will change from the Bourne shell '$' to '%'.

$ /bin/csh
%

This is convenient for occasionally switching shells, but what if we want to change the user account default shell?

User account information is stored in the passwd file found in /etc. Passwd contains the user's login name, password, and other information including the program to use as shell. You can read more about it in the passwd man page.

Changing the user's default shell is pretty simple. Switch to the root account with "su", edit the /etc/passwd file with "vi", find the line for the desired user account, and add the path to the shell program at the end of the line.

guest::7:3::/usr/guest:/bin/csh

Change the shell for "guest" to "/bin/csh".
Exit the root account, logout of your account, and log back in. You should now be in the new default shell.

Running the C shell by default