Review of .cshrc file - Check the .cshrc file for some of the examples of commands that are put in .cshrc file - if you make changes to the .cshrc file they will take effect for the next instance of csh - if you want the cahnges to be effective in the curent shell, use source command as in: source .cshrc - Some of the important points of the sample .cshrc are as follows - variables prompt was set to give us a prompt that includes name of the machine, followed by path given by the variable $cwd followed by the command number - the variable history is used to remember last few commands - the variable filec allows file name completion using escape key - see some of the simple aliases - we will study more complicated aliases after learning more about shell variables VARIABLES - Shell is a programming language. Like any other programming language it allows us to use variables - There are some variables used by the system. You can set the values of those. - These system variables include: path, home, cwd, prompt - command setenv gives you a list of all your environment variables wascana/extra/pawan 11 >echo $cwd /extra/pawan wascana/extra/pawan 12 >echo $pwd pwd: Undefined variable. wascana/extra/pawan 13 >echo $PWD /extra/pawan wascana/extra/pawan 14 >echo $html /usr/local/etc/httpd/htdocs/pawan wascana/extra/pawan 15 >set my_name=pawan wascana/extra/pawan 16 >echo $my_name pawan wascana/extra/pawan 17 >set my_name=pawan lingras wascana/extra/pawan 18 >echo $my_name pawan wascana/extra/pawan 19 >set my_name='pawan lingras' wascana/extra/pawan 20 >echo $my_name pawan lingras - We used the command set to set variables - command unset allows you to remove a variable ALIASES INVOLVING VARIABLES - The alias cd sets a variable (not system variable) to be equal to current working directory; changes directory to the one specified by arguments to the alias cd (\!* stands for the argument list); finally the prompt is properly set alias cd 'set old=$cwd; chdir \!*; set prompt = "wascana"$cwd" \! >"' - The alias back takes us back to the previous directory. A variable called back is used to temporarily store the value of old; old is set to current working dir; dir is changed to the value stored in back; variable back is unset. alias back 'set back=$old; set old=$cwd;cd $back; unset back; dirs' - The following faculty alias cats all the files specified in the argument list to an rsh command alias faculty 'cat \!* | rsh -l lingras tbird faculty' - rlogin and rsh commands - rlogin can be used to login to any other UNIX computer on the internet. If the user on the remote machine has a .rhost file such as: wascana/extra/pawan 1 >more .rhosts satara.auc.on.ca pawan satara pawan - User pawan from satara.auc.on.ca can login without any password - rlogin machine-name [-l username] - if the username is not specified, the same username as the current machine is used - if there is no .rhosts entry, a password is required - rsh (remote shell) allows you to run a single command on remote host - rsh will work only if there is .rhosts entry - Another related file is /etc/hosts - It has ip numbers for some of your favourite machines SCRIPT - script command starts a shell session - script filename - puts all the information in the file filename - if you don't specify the filename then the name typescript is used - If you start the command with a #, shell ignores that command line. Similar to comments in programming languages - echo echoes whatever follows $ echo hello world hello world $ SCREEN - screen allows you to have multiple interactive shell sessions - CTRL-A is trapped by the screen. Next character is expected to be a screen command. - ? gives you a list of commands - c to create a new window - space to go to the next window - digit to go to a particular window numbered as that digit such as 0 1 2 3 4 .... - k to kill a window, d to detach the screen - The detached screen is in the memory as long as su doesn't kill it or the machine doesn't get rebooted. - You can recover a detached screen using "screen -r" - You can have several detached screens at the same time - file redirection - > allows you to redirect output to a file instead of your screen - < allows you to specify that input will be coming from a file instead of keyboard $ echo hello world > temp You have mail $ cat temp hello world - >> is similar to >, but appends instead of overwriting the file $ echo I am fine >> temp $ cat temp hello world I am fine $ - If you wanted the error messages to be redirected to the file you use >& - Each program has three files open stdin is for input (by default it is the keyboard), stdout is for output (by default it is the screen), stderr is for error (by default it is the screen) - < changes the default stdin from keyboard to a file - > changes the default stdout from screen to a file - >& changes the default for stdout and stderr from screen to a file. wascana/extra/pawan 25 >cp cp: missing file arguments Try `cp --help' for more information. wascana/extra/pawan 26 >cp > cp_errors cp: missing file arguments Try `cp --help' for more information. wascana/extra/pawan 27 >more cp_errors wascana/extra/pawan 28 >rm cp_errors /bin/rm: remove `cp_errors'? y wascana/extra/pawan 29 >cp >& cp_errors wascana/extra/pawan 30 >more cp_errors cp: missing file arguments Try `cp --help' for more information. - piping can be used to send output from a program as input to another program $ who > temp $ sort < temp $ who | sort - You can run more than one command on the same line $ date;who - ; is a command terminator - You can run one command over several lines by using \ as continuation character $ w\ > ho doorman pts/1 Jan 9 05:34 osei pts/9 Jan 10 20:41 eagle pts/7 Jan 10 21:12 crumplin pts/11 Jan 10 21:02 phone pts/21 Jan 9 18:45 matthews tty14 Jan 10 20:48 chin tty15 Jan 10 21:08 lingras pts/10 Jan 10 19:03 lingras pts/28 Jan 10 19:10 lingras pts/30 Jan 10 19:10 $ - Running processes in the background by appending & to the command see page 33 - ps gives you list of all the processes associated with the current terminal - ps -f gives you a full listing - full listing has the process id and parent's process id - ps -u username gives you a listing of all the processes the user username is running - kill nnnnn kills the process with pid=nnnnn - kill -9 nnnnn can kill any of your processes - look at the nice command, at command on page 35 - nice followed by the command name allows you to reduce the priority of the process - su can increase the priority using nice - CTRL-C can be used to cancel a command - CTRL-D is end of file. Sometimes when the command is expecting input from your keyboard CTRL-D will terminate the command - CTRL-Z is used to stop a job. The job is suspended. - bg can be used to put the suspended job in the background - fg can be used to bring the suspended job in the foreground - at command allows you to run a command at a particular time at 11:00am type the commands here on hit CTRL-D when done - The commands you typed will be run at 11:00am - If you want you can have the commands in a file at 11:00am < filename - crontab is the utility that you may want to use to schedule jobs to be run at a particular time - We will look at the format of crontab later on SIMPLE SHELL SCRIPTS - .cshrc is an example of a shell script - csh they accept input from a file - csh filename - if you don't specify the filename SU activity Creating an account Modifying/Creating a group Changing/Adding Messages of the Day