Lab 4- Shells & Scripting

 

Shell Basics

1.       Command Options and Arguments and command entry:

·         ls –l

·         ls –l –a   vs.   ls –la

·         ls \  -l

·         ls –ld mail

 

2.       Standard Output, Standard Error and Standard Input and Redirection:

·         ls –l > ls-l.txt

·         ls –l thisfile usethis

·         ls –l thisfile usethis > ls.txt

·         ls –l thisfile usethis >& /dev/null

·         ls –l thisfile usethis >& ls2.txt

·         ls –l thisfile usethis >& ls3.txt

 

3.       Pipes and Filters:

·         ls –l |grep ^d

·         ls –l / |more

·         (telnet classes) ps -ef

·         ps –ef |sort |more

 

4.       Filename generation:

·         ls –l l*

·         ls –l l?.txt

 

5.       Shell variables:

·         set MYVAR=UNIX

·         echo MYVAR

·         echo $MYVAR

·         set MYVAR=UNIX Rocks!!!

·         set MYVAR=“UNIX Rocks!!!”

·         echo $MYVAR

·         set

·         (csh) set

·         exit

·         setenv MYVAR=“UNIX Rocks!!!”

·         (csh) set

·         nslookup cs1970.lsu.edu

·         setenv PATH "$PATH":/usr/sbin

·         nslookup cs1970.lsu.edu

 

 

C Shell

1.       Protection:

·         ls –l > ls-l.txt

·         set noclobber

·         ls –l > ls-l.txt

·         (csh)

·         <CTRL-D>

·         (csh)

·         set ignoreeof

·         <CTRL-D>

 

2.       Command History:

·         history

·         set history=300

·         set savehist=100

·         ls –l

·         !!

·         !-4

·         !! |grep set

 

3.       Aliases:

·         ls –lA

·         alias myls ls –lA

·         myls

·         alias

·         unalias myls

·         myls

 

4.       Job Control:

·         find / -name *log* -ls  (<ENTER> then <CTRL-C>)

·         find / -name *log* -ls &

·         find / -name *log* -ls > find-logs.txt &

·         jobs

·         find / -name *log* -ls >& find-logs2.txt &

·         jobs

·         kill %2

·         jobs

·         fg %1

·         <CTRL-Z>

·         bg

·         kill 0

·         jobs

 

5.       Filename completion:

·         set filec

·         ls –l .pi<ESC>

 

6.       Autorun scripts:

·         ls –l .login .cshrc

·         cat .login

·         cat .cshrc

 

C Shell Scripts

1.       Shell script to print greeting.

2.       Modify to print based on a.m. or p.m. (date +%H)

3.       Modify to ask for name

4.       Modify to check arguments (use as name)

5.       Add to .login

6.       telnet to test