Lab 4- Shells & Scripting

 

Shell Basics

1.       Command Options and Arguments and command entry:

         ls 僕

         ls 僕 紡 vs. ls 僕a

         ls \ -l

         ls 僕d mail

 

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

         ls 僕 > ls-l.txt

         ls 僕 thisfile usethis

         ls 僕 thisfile usethis > ls.txt

         ls 僕 thisfile usethis >& /dev/null

         ls 僕 thisfile usethis >& ls2.txt

         ls 僕 thisfile usethis >& ls3.txt

 

3.       Pipes and Filters:

         ls 僕 |grep ^d

         ls 僕 / |more

         (telnet classes) ps -ef

         ps 貌f |sort |more

 

4.       Filename generation:

         ls 僕 l*

         ls 僕 l?.txt

 

5.       Shell variables:

         set MYVAR=UNIX

         echo MYVAR

         echo $MYVAR

         set MYVAR=UNIX Rocks!!!

         set MYVAR=填NIX Rocks!!!

         echo $MYVAR

         set

         (csh) set

         exit

         setenv MYVAR=填NIX Rocks!!!

         (csh) set

         nslookup cs1970.lsu.edu

         setenv PATH "$PATH":/usr/sbin

         nslookup cs1970.lsu.edu

 

 

C Shell

1.       Protection:

         ls 僕 > ls-l.txt

         set noclobber

         ls 僕 > ls-l.txt

         (csh)

         <CTRL-D>

         (csh)

         set ignoreeof

         <CTRL-D>

 

2.       Command History:

         history

         set history=300

         set savehist=100

         ls 僕

         !!

         !-4

         !! |grep set

 

3.       Aliases:

         ls 僕A

         alias myls ls 僕A

         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 僕 .pi<ESC>

 

6.       Autorun scripts:

         ls 僕 .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