Shell Scripting .

Uploaded on:
Category: Travel / Places
Motivation. IntroductionUNIX/LINUX and ShellUNIX Commands and UtilitiesBasic Shell Scripting StructureShell ProgrammingVariableOperatorsLogic StructuresExamples of Application in Research ComputingHands-on Exercises. The PPT/WORD arrangement of this presentation is accessible here:
Slide 1

Shell Scripting Shubin Liu, Ph.D. Inquire about Computing Center University of North Carolina at Chapel Hill

Slide 2

Agenda Introduction UNIX/LINUX and Shell UNIX Commands and Utilities Basic Shell Scripting Structure Shell Programming Variable Operators Logic Structures Examples of Application in Research Computing Hands-on Exercises The PPT/WORD organization of this introduction is accessible here:

Slide 3

Why Shell Scripting ? Shell scripts can be utilized to get ready info records, work observing, and yield handling. Valuable to make possess summons. Spare loads of time on document preparing. To computerize some errand of everyday life. Framework Administration part can be additionally mechanized.

Slide 4

Objectives & Prerequisites After this workshop, you ought to be: Familiar with UNIX/LINUX, Borne Shell, shell factors/administrators Able to compose straightforward shell scripts to delineate programming rationale Able to compose scripts for research processing purposes We expect that you have/know A record on the Emerald group Basic information of UNIX/LINUX and orders UNIX editorial manager e.g. vi or emacs

Slide 5

History of UNIX/Linux Unix is a summon line working framework created around 1969 in the Bell Labs Originally composed utilizing C Unix is planned with the goal that clients can extend the usefulness To manufacture new instruments effortlessly and productively To modify the shell and UI. To string together a progression of Unix orders to make new usefulness. To make custom orders that do precisely what we need. Around 1990 Linus Torvalds of Helsinki University began off an unreservedly accessible scholastic rendition of Unix Linux is the Antidote to a Microsoft commanded future

Slide 6

What is UNIX/Linux ? Essentially put Multi-Tasking O/S Multi-User O/S Available on a scope of Computers SunOS Sun Microsystems IRIX Silicon Graphics HP-UX Hewlett Packard AIX IBM Linux … .

Slide 7

UNIX/LINUX Architecture

Slide 8

What is a "Shell"? client Shell client OS client The "Shell" is just another program on top of the portion which gives an essential human-OS interface. It is an order mediator Built on top of the portion Enables clients to run administrations gave by the UNIX OS In its least complex frame, a progression of charges in a document is a shell program that recoveries having to retype summons to perform normal errands. The most effective method to realize what shell you utilize resound $SHELL

Slide 9

UNIX Shells sh Bourne Shell (Original Shell) ( Steven Bourne of AT&T ) bash Bourne Again Shell ( GNU Improved Bourne Shell ) csh C-Shell (C-like Syntax)( Bill Joy of Univ. of California ) ksh Korn-Shell (Bourne+some C-shell)( David Korn of AT&T ) tcsh Turbo C-Shell (More User Friendly C-Shell). To check shell: $ reverberate $SHELL (shell is a pre-characterized variable) To switch shell: $ executive shellname (e.g., $ executive bash or basically sort $ bash ) You can change starting with one shell then onto the next by simply writing the name of the shell. leave return you back to past shell.

Slide 10

Which Shell to Use? sh ( Bourne shell) was viewed as better to programme csh (C-Shell ) was viewed as better for intuitive work. tcsh and korn were changes on c-shell and bourne shell separately. bash is to a great extent good with sh and furthermore has a hefty portion of the pleasant elements of alternate shells On numerous frameworks, for example, our LINUX groups sh is typically connected to bash,/receptacle/sh - >/canister/bash We prescribe that you utilize sh/bash for composing new shell scripts yet learn csh/tcsh to comprehend existing scripts. Many, if not every, logical application require csh/tcsh condition (GUI, Graphics Utility Interface) All Linux variants utilize the Bash shell (Bourne Again Shell) as the default shell Bash/Bourn/ksh/sh incite: $ All UNIX framework incorporate C shell and its forerunner Bourne shell. Csh/tcsh provoke: %

Slide 11

What is Shell Script? A shell script is a script composed for the shell Two key fixings UNIX/LINUX summons Shell programming sentence structure

Slide 12

A Shell Script Example #!/canister/sh ` ls - l *.log| awk \'{print $8}\' | sed \'s/.log//g\' > file_list ` feline file_list| while read each_file do babel - ig03 $each_file".log" - oxyz $each_file".xyz" resound \'# nosymmetry integral=Grid=UltraFine scf=tight rhf/6-311++g** pop=(nbo,chelpg) \'> head reverberate " >>head resound "" $each_file\' pick pop nbo chelp point charges " >> head reverberate " >>head reverberate " 0 1 " >>head ` sed "1,2d" $ > garbage ` input= ./$each_file " .com " feline head > $input feline garbage >> $input reverberate " >> $input done/container/rm ./garbage ./head ./file_list #!/receptacle/sh ` ls - l *.log | awk \'{print $8}\' | sed \'s/.log//g\' > file_list ` feline file_list |while read each_file do babel - ig03 $each_file".log" - oxyz $each_file".xyz" reverberate " # nosymmetry integral=Grid=UltraFine scf=tight rhf/6-311++g** pop=(nbo,chelpg) \'> head reverberate " >> head resound "" $each_file\' select pop nbo chelp point charges " >> head reverberate " >> head reverberate " 0 1 " >> head ` sed "1,2d" $ > garbage ` input= ./$each_file " .com " feline head > $input feline garbage >> $input resound " >> $input done/container/rm ./garbage ./head ./file_list

Slide 13

File Management and Viewing Filesystem Mangement Help,Job/Process Management Network Management System Management User Management Printing and Programming Document Preparation Miscellaneous UNIX/LINUX Commands To comprehend the working of the order and conceivable choices utilize ( man summon) Using the GNU Info System ( data , information charge) Listing a Description of a Program ( whatis summon) Many apparatuses have a long−style alternative, ` −−help \', that yields use data about the instrument, including the choices and contentions the device takes. Ex: whoami - help

Slide 14

File and Directory Management compact disc Change the present catalog. Without any contentions "cd" changes to the clients home catalog. (compact disc <directory path>) chmod Change the document authorizations. Ex: chmod 751 myfile : change the document consents to rwx for proprietor, rx for gathering and x for others ( x=1,r=4,w=2 ) Ex: chmod go=+r myfile : Add read authorization for the gathering and others (character implications u-client, g-assemble, o-other, + include consent,- remove,r-read,w-write,x-exe) Ex: chmod +s myfile - Setuid bit on the record which permits the program to keep running with client or gathering benefits of the record. chown Change proprietor. Ex: chown <owner1> <filename> : Change responsibility for record to owner1. chgrp Change amass. Ex: chgrp <group1> <filename> : Change gathering of a document to group1. cp Copy a document starting with one area then onto the next. Ex: cp file1 file2 : Copy file1 to file2; Ex: cp –R dir1 dir2 : Copy dir1 to dir2

Slide 15

File and Directory Management ls List substance of a catalog. Ex: ls, ls –l , ls –al, ls –ld, ls –R mkdir Make a registry. Ex: mkdir <directory name> : Makes an index Ex mkdir –p/www/chache/var/log will make every one of the registries beginning from www. mv Move or rename a document or index. Ex: mv <source> <destination> discover Find records (find <start directory> - name <file name> - print) Ex: find/home –name readme - print Search for readme beginning at home and yield full way, "/home" = Search beginning at the home registry and continue through every one of its subdirectories; "- name readme" = Search for a document named readme "- print" = Output the full way to that record find File finding program that uses the slocate database. Ex: find –u to make the database, find <file/directory> to discover record/catalog

Slide 16

File and Directory Management pwd Print or rundown the present working registry with full way. rm Delete documents (Remove records). (rm –rf <directory/file>) rmdir Remove an index. The catalog must be vacant. (rmdir <directory>) touch Change document timestamps to the present time. Make the record on the off chance that it doesn\'t exist. (touch <filename>) whereis Locate the paired and man page documents for a summon. (whereis <program/command>) which Show full way of charges where given orders live. (which <command>) File survey and altering emacs Full screen supervisor. pico Simple word processor. vi Editor with a charge mode and content mode. Begins in summon mode. gedit GUI Text Editor tail Look at the last 10 lines of a document. Ex: tail –f <filename> ; Ex: tail - 100 <filename> head Look at the initial 10 lines of a document. (head <filename>)

Slide 17

File and Directory Management File pressure, going down and reestablishing pack Compress information. uncompress Expand information. cpio Can store documents on tapes. to/from documents. gzip - compress a document to a gz record. gunzip - unfasten a gz document. tar Archives documents and indexes. Can store records and registries on tapes. Ex: tar - zcvf <destination> <files/directories> - Archive duplicate gatherings of documents. tar –zxvf <compressed file> to uncompress compress – Compresses a record to a .compress document. unfasten – Uncompresses a record with .compress expansion. feline View a record Ex: feline filename cmp Compare two documents. cut Remove areas from each line of records.

Slide 18

File and Directory Management diff Show the contrasts between documents. Ex: diff file1 file2 : Find contrasts between file1 & file2. resound Display a line of content. grep List all records with the predetermined expression. ( grep design <filename/directorypath >) Ex: ls –l |grep sidbi : List all lines with a sidbi in them. Ex: grep " R " : Search for R with a space on each side rest Delay for a specifie

View more...