Вы находитесь на странице: 1из 16

1) 1) activate different shells:

IN UNIX execute
/usr/bin/tcsh
/usr/bin/sh
/usr/bin/csh
Type ps to see which shells are active.
You change your shell with the command exec csh.
you use the csh shell instead of the current one
Type ps to see that you changed your shell)

That will let

UNIX environments have different shells (command-line user interfaces),


depending upon the implementation. Get some information on the Bourne (sh)
shell. Different shells have different prompts.
What are the prompts for each of the csh, sh, and tcsh shells?

tcsh prompts to give >


sh prompts to give $
csh prompts to give %
Bourne shell is a command line interpreter for computer operating systems.It is orginal uix shell.
It is denoted by sh. Bourne shell scripts can typically be run with bash on GNU /Linux or other
Unix-like systems.

2) The Linux environment is a little different.


Execute ps to see that the default shell is bash (Bourne again shell)
You can create new shells by typing the shell identification on the command
line
(i.e., sh) to create a new shell interface
try a few
sh
csh
bash
then type
ps
to see that you have multiple shells available. Although most shells recognize
the same basic commands, there are considerable differences as we will see.
To change to the C (or enhanced C) shell use the command
chsh
or
chsh -s /bin/csh
Either will require elevating your privileges by entering your password and
logging out and in again - if they work.
(execute the command
echo $SHELL
to see if the shell was changed).

3. Try grep commands in UNIX and Linux to get used to using flags such as

{-i, -n} and other constructs. You can use multiple flags for the same command

Grep command selects and prints the lines from a file which matches the given string.

grep <pattern> *

: list all occurrences of <pattern> in


current directory

grep "pattern" *

: use quotes if a blank occurs within the pattern

grep -i <pattern> <file> : the -i flag provides case insensitivity.


test an upper case pattern against a document that
contains that pattern in lower case.

grep -n <pattern> <file>: the -n flag will output the line number as well
as the pattern in the file

LINUX:

4) Use a pipe and the tee command (these are valid in all three
environments)
tee saves intermediate results in a file, for example:
grep cd * | tee temp | wc
will place the occurrences of cd inside temp and print the word count
of temp on the terminal.
Output the temp file.

A pipe ( | ) allows partial output to begin to be processed by another


process.
Try:

man grep | more

The above will pipe the output of the help (man) file one page at a time to
the
terminal. DO NOT PRINT THIS FILE OUT.

5) Pipes work in the Windows command prompt.


In command prompt try
ipconfig | more | find "IPv4"
or just plain
ipconfig | find "v4"

In Windows Powershell execute


ipconfig | more | findstr "IPv4"

6) create a small file in UNIX or Linux called


Within the file place the command
echo hello

firstscript

Close the file and make it executable (chmod 700 firstscript)

execute the file:


firstscript
Now parameterize the file by changing the file data to
echo $1

Execute the file with a string following the file name


such as
./firstscript hello-Dr.Levine

Now try it with spaces in the parameters, i.e., hello Dr. Levine
You'll see that UNIX terminates input upon finding a blank, such as when
you execute
.Levine

three
echo
echo
echo

lines of data with parameters in the file.


$1
$2
$3

Now execute the file with 3 parameters


./firstfile hello Dr. Levine

one line of data with parameters in the file and execute the file with
3 parameters:
echo $1 $2 $3

The difference is in the first data is executed in three lines.


Whereas in the later it is executed in single line.

The difference is in the first data is executed in three lines.


Whereas in the later it is executed in single line.

7) You are going to create another small shell script called secondscript.
Choose one of your existing files in the current directory (say child.c)
and write that name into secondscript for compilation and execution:
rm ./a.out
cc ./child.c
./a.out &
Ps

Assign execution rights to secondscript and execute it.

Parameterize this script by replacing the command


cc ./child.c
with the line
cc $1

Execute secondscript with the filename as a parameter, such as


./secondscript ./child.c

8)
In UNIX or Linux write a shell script for creating a copy of a given
(nonempty)
file, where the copy has each line numbered. Do this by
printing out the file with a line number (cat -n) and redirecting it
to another filename.
cat -n "filename" > newfile
Then print out the new file on the terminal.
Don't forget that you must specify the path in our Linux system, but not
in our UNIX environment. (the path includes your current directory)

9)In Windows 7 command prompt,


create a file with a .bat extension (say batchfile.bat). This makes the file
automatically executable. See if there is an editor (EDIT) in command prompt.

10) Research Linux frameworks.


Explain what a Linux framework is.
their operating systems?

How does it help developers customize

A Linux-based system is a modular Unix-like operating system. It derives much of its basic design from
principles established in Unix. Such a system uses a monolithic kernel, the Linux kernel, which handles
process control, networking, and peripheral and file system access. Device drivers are either integrated
directly with the kernel or added as modules loaded while the system is running.
Separate projects that interface with the kernel provide much of the system's higher-level functionality.
The GNU user land is an important part of most Linux-based systems, providing the most common
implementation of the C library, a popular CLI shell, and many of the common Unix tools which carry out
many basic operating system tasks.
The best feature of Linux Framework is its low susceptibility to virus and malware infestation. Linux is
almost always a free operating system with multiple sources distribution. In contrast, Windows and Mac
OS X are some of the most expensive operating systems available. Linux is an open source platforms
with plenty of developers working on applications, functions, features and add-ons that are guaranteed to
improve your user experience.
.

Вам также может понравиться