0% found this document useful (0 votes)
3 views

Linux Unit 4.2 notes

The document provides an overview of shell interfaces in Linux, explaining their role in executing commands and scripts. It discusses various shell types, command prompts, and features such as input/output redirection and piping. Additionally, it outlines the steps for creating and running shell scripts, highlighting their advantages and disadvantages.

Uploaded by

rekhadhone4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
3 views

Linux Unit 4.2 notes

The document provides an overview of shell interfaces in Linux, explaining their role in executing commands and scripts. It discusses various shell types, command prompts, and features such as input/output redirection and piping. Additionally, it outlines the steps for creating and running shell scripts, highlighting their advantages and disadvantages.

Uploaded by

rekhadhone4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 38
‘A shell provides you with an interface to the ‘which we can run our commands, a ‘The shell is not part of system kernel, but thers input from you ie operating system ene it displays ta A shell provides you with an interface to apie Sproeraln finishes &* ‘thay and shell scripts. There an ‘executes programs based on that input. program's output. as, programs, Beles gn ecronment in which we can rin UF COMIDAI™S™ TTY Co rating aysternly Hacdt Zistmteg different favors of a shell, just as there are different “Te shell has its own set of recognized commands and fun Several shells are available for Linux including: pen source. BASH (Bourne-Again SHell): Most common shel gramming languag shel usage are very 3 iso waa tal al a et ATAT Bell Lab. The or SS 7 the POSIX Shell standard specifications. the Berkeley UNIX C shell C39, 4, TCSH: Itis an enhanced but completely compatible version ° Shell Prompt © The prompt 5, which is called the command prompt i issued ¥ a displayed, you can type a command, There ae various ways o get shel act } 1. Terminal: Linux desktop provide a GUI based login system. Once logged in You SA BA EAA a shell by running X Terminal (KTerm), Gnome Terminal (GTex™), oF (Clera) application by pressing ctr+alt+T keys on Keyboard. Connect via Secure Shell (SSH): You will get a shell prompt as server or workstation. 3. Use the Console: A few Linux system also provides a text-based login system. Generally yougeta shell prompt as soon as you log into the system. © Limuchas two prompts stored in PS1 and PS2. The primary prompt string PS1 is the one you normally see (6). The secondary prompt string (>) indicated by PS2. You can easily change your prom) character at any time simply by changing the value of the shell variable PS oa $ echo $51 \\f\el@s\ua\h: \w\a\Js{debtan_chroot:+(sdebtan_chroot)}\{\e3 [3feas32n\ }\ve\h\[\033f00n\ :\L\033[61534n\]\w\[\e33[e0n\]\$ echo SPs2 yy the shell. While the prompt jg soon as you log in into remote ‘Apr 24 22:48:43 POT 2019 it «Use exit command to come out of this. sh Command ‘The shell is a command that reads lines from generally executes other commands, It is the program that is running when a us different shell with the chsh(1) command), either a file epyeorRR eibieuaia R\° 4, sh is the command name of the Bourne shell, the standard command ____ Unixand many Unix-like operating systems, including Linux. _ 2, bash is the command name of the Bourne Again SHell, the standard interpreter of Unix and many Unix-like operating systems, including Linux: Bash stands for "Bourne Again SHell”, and is a ‘replacement/improvement of the shell (sh). The results of commands can be different depending on which interpreter is called: 28.80 - commands will work in sh, whereas most sh commands’ ‘will work in bash. Switching of one flavor of shell to another is simple possible by ‘using shell command. ¢ Use sh command to switch from "Bourne Again SHell’, to Bourne shell 6H) Use bash command to switch from Bourne shell (sh) to "Bourne Again ‘sHell", Fxample: Switching of shels. 5 " though they are intended to be executed’ as basit 1] shell scripts have ‘the suffix sh, even a nes ‘at the top of the script. It actually does not ‘matter whether the script is script, what matters is whether the call to the interpreter is /bin/sh or Join /bash. Shell scripts can also pe called on the command line with either ‘sh or bash. it b Pattern Matching (Wild Cards) scripts, and have called scriptsh or my“ Wildcards are a set of puilding blocks that allow yo directories. pelong toa cates’ ‘© The shell has the “his ve of the characters xy oo it rang! or share corn “ond single che ae fl ‘the characte)’ ingle characte © tis nota nijork ita mao ‘asingle character that 8 2% with! a bea) Lak) : [x2] and. (pata, pat2, atl, pa | ai abc a22 any | chap1 chap2 chap3 chapg TPolist all files beginning with chap | chapter | ab xy 12 | 3, | listall the filenames which have a filename | 15 ? [Poise filename chapt chap4 chaps Fs retse tennessee chaps chape chaps | cher 245]_| chap2 chaps CAS Sp %.__| Tolist filename from chapS to chap? _ 1s chapl5-7] (cas eeeme ap? | Se Te Tarai porn tie range rom chaps [1s chap 5-7) | chap3 chap chap@ has tochap? es ae Example: Using wild cards. Sis tw | me 23 Apr 23 23:24 nanelists me 25 Apr 23 23:25 naneltst2 me 131 Apr 24 22:33 newftle | me 82 Apr 24 22:45 newftlet Sewer ewer ror: |-rw-r- EER] quoting 1. Single Quotes | * When echo command is used by placing all the characters in the argume string is displayed as its and no substitution of characters occurs, oe In following example fruit a variable having value as banana peecicteaa)caranteriocnt nana, Echo command is used to display tM a § fruit=banana ibe t-$ echo 'Thts ts a $frutt'| [This ts @ Sfruit nt within single quote, tht + Thevalue of variable frult is not displayed since the strin Double Quotes: 8 is enclosed in single quote. * By enclosing variables that are specified as ar; are substituted with thelractual values, ™*"* © command in double quotes the vat sevesee? Substitution, Pein ou ism another comm CuI the place oft command using Accent commands. It allows a user ett Snane today’s date ts The ape ae * The term redirection encompasses the various ways you can cause the shell to alter where standard input of a command comes from and where standard output goes to. * The data in input and output operations is organized like a file. Standard input is 2 place that = program gets information from. Standard output is a place that a program can send information, such as text. * Data input at the keyboard is placed in a data stream as a continuous set of bytes while data output from a command is also placed in a data stream and arranged as a continuous set of bytes * This input data stream is referred to in Linux as the standard input and the output data stream i called the standard output. * Inall operating systems, there i {display screen). Redirection can for input. ; B comerimes, you want to save the output of « command toa location rather than SDS am Beenitor, The shell provides a few different operators that allow, You) assests the output of a ‘command to an alternative location. it Redirection ee output from a command tea file. Output redirection is ‘The most basic type of redirection is sending .-than symbol (>). cy ; = ee ‘a. command to writes (display) its output, It is denoted by one number (2) ‘Standard outpu : See mand with redirection operator (>) to ay used cat com ‘Chapter 1, we have already ust . pero use output redirection 88 follows: $ command > output file is a standard input device (keyboard) and a standard output device be used for input as well as output, redirecting a file toa command he he then previous contents. 1f you Se fs f eT ie nese This time the output of commat _- say created the file “dematp! “ a _ =ar which will creat eden | Hrs fist we areusing ne comsand TS Soe. Ue oH Command to confimm fy Tea redirected the ouput of date command f° Sontent of demote Nest ws are suing whoam command with redirect © Semnand wil ote the contents of emote mote” BEER] input Redirection Tinpatrecirection is opposite Tedlrecton Input redirection takes the content Safle and reiecsitfoa command Mio Known as stdin Tels denoted by 270 umber (0) Taput redirection is represented by Jess-than symbol (<). The syntax to use Input redirection is as follows Seerelspitrite ig. 33 shows redirecting standard input : Coonalll “ " is already created, th ator. As “demofile” is already q cs te cnt tec of output Fig.3.3 Example 1: wo and sort command without redirection = standard input. ection. Normally we and sort command works é| first we are creati aia cee "The we command provides Peimenumberoflinesinthete ‘¢ Thenumber of words in the text. fe Thenumber of bytes in the text. ‘The sort command will sort the content of “afile” and display the sorted result ', There's another method of input redirection, called inline input redirection. This method allows Jou tospecify the data for input redirection on the command line instead on 8 AX |, Inline input redirection is represented by double less-than symbol (<<). You must specify a text marker that delineates the beginning and end of the data used for input, |, The syntax to use inline input redirection is as follows: command << marker date marker 4: Using inline input redirection. ‘same line, eee —— ______—Foutput redirected. The output ‘of sort

You might also like