S E C T I O N O V E R V I E W

Size: px
Start display at page:

Download "S E C T I O N O V E R V I E W"

Transcription

1 AN INTRODUCTION TO SHELLS S E C T I O N O V E R V I E W Continuing from last section, we are going to learn about the following concepts: understanding quotes and escapes; considering the importance of the shell; introduces shell s syntax; obtaining user input; passing data into scripts; performing simple arithmetic; fundamentals of shell programming. 7.1 QUOTES AND BACKQUOTES In UNIX shells, there are several characters that have special meaning. These include the dollar sign ($), the greater that (>), less than (<), the ampersand (&) and so on. Each of these serves some kind of functionality. For example, the dollar sign ($) allows us to access the contents of a variable while the greater (>) and less (<) than characters reflect output and input redirection. The set of all characters that have a special meaning for UNIX shells, are known as meta-characters. These are: *? [ ] \ $ ; & ( ) ^ < > new-line space tab FIGURE 6.1: Meta-characters Although, these characters are interpreted by shells with this certain functionality, we may wish to use them as regular ones. For instance, we may wish to display a string on our terminal window that corresponds to the PAGE 1

2 currency of the USA or we would like to display a sentence that describes inequality between two numbers. This can be shorted out by the use of some special characters that indicate the system our intentions. More precisely, these characters are the single quote ( ), double quote ( ) and the backslash (\) symbol. In other words, these characters override the preserved functionality of all meta-characters. Let us consider an example: 1 tiger% echo Hello ; world Hello world: Command not found 2 tiger% SAMPLE OUTPUT 7.1: USING ECHO WITH ; CHARACTER In sample output 7.1, the shell echoed Hello on the terminal display. However, it did not echoed world. The reason of getting this result corresponds to that the shell tried to execute command world. Recalling back from previous sections, the meta-character ; allows us to execute UNIX commands sequentially. Now, let us attempt to override the functionality of semicolon (;) symbol and indicate the shell that we need to echo the string Hello ; world on our terminal window. This is shown in sample output tiger% echo Hello \; world Hello ; world 5 tiger% echo Hello world Hello world 6 tiger% echo Hello world Hello world 7tiger% SAMPLE OUTPUT 7.2: USING ECHO WITH \ ; CHARACTER In this case, we used the backslash symbol followed by the semicolon symbol. This instructed the shell to consider (;) as a semicolon and displayed it on our terminal window. Therefore, world was not considered as a UNIX command by the shell. Of course, as an alternative solution we can use single PAGE 2

3 or double quotes. The result after the execution, as shown, is exactly identical. However, each of these symbols is used differently. Typically, if we wish to use any of the meta-characters shown in figure 7.1 overriding any functionality ascribed to them, we need to use either quotes or the backslash symbol. Quotes are often used for strings while backslash is used with single characters. 11 tiger% set VAR = 'Hello <$NAME>' 12 tiger% echo $VAR Hello <$NAME> 13 tiger% SAMPLE OUTPUT 7.3: VARIABLES INCLUDED IN OTHER VARIABLES In sample output 7.3, we attempted to define a variable that contains a reference of another variable in it. However, the execution of the output did not have the expected outcome. The reason is well known as it has been elaborated previously. Now the problem is to find out how we can achieve that having a reference of a variable in the context of another variable. This can be carried out by the use of brackets that have a special meaning for UNIX shells. 1 tiger% set NAME = Tom 2 tiger% echo $NAME Tom 3 tiger% set HELLO = ('Hello ' $NAME) 4 tiger% echo $HELLO Hello Tom 5 tiger% set HELLO = ("Hello " $NAME) 6 tiger% echo $HELLO Hello Tom 7 tiger% set NAME = Ioannis 8 tiger% echo $HELLO Hello Tom 9 tiger% set HELLO = ('Hello ' $NAME) 10 tiger% echo $HELLO Hello Ioannis 11 tiger% SAMPLE OUTPUT 7.4: USING ECHO WITH \ ; CHARACTER Initially, we defined a variable called NAME and assigned the value Tom into it. Then, we set up a new variable called HELLO. However, the PAGE 3

4 most important point here is that HELLO variable contains a reference of NAME variable. In order to complete its definition, we had to use brackets. Moreover, the string hello was separated from variable $NAME by the use of double quotes. Next, we echoed HELLO variable and we obtained the expected result. Another important point here is that when we decided to change the value of the variable NAME, we initially thought that echoing HELLO would refer to the updated value of variable name. This did not happen initially. However, when we redefined variable HELLO, the expected result was obvious. To this extent, we can conclude that when a variable contains a reference of another variable, the assignment of a value to the former variable happens statically and cannot change dynamically i.e. when we redefine the included variable in the context of another variable. Moreover, when we use quotes we need to remember to close them as shells match an initial single quote with the nearest possible ending single quote. Therefore, although we are allowed to use single quotes into a quoting string, there are ignored by the shell. 14 tiger% set TEST = 'Hello '' how are you' 15 tiger% echo $TEST Hello how are you 16 tiger% set V = 'Hello Unmatched ' 17 tiger% SAMPLE OUTPUT 7.5: WORKING WITH SINGLE QUOTES In sample output 7.5 we can see that csh ignored two single quotes placed in the quoting string. Moreover, when we attempted to define variable V, we did not close the quoting string before pressing the <RETURN> key. This resulted in the generation of an error. A suggestion here is that we need to use as less as possible single quotes in a statement. In Bourne shells, there are some differences. For example, forgetting to close a single quote will result in the appearance of the continuation prompt. This actually informs us to close an opening single quote. PAGE 4

5 $ MYVAR='Hello > world' $ echo $MYVAR Hello world $ SAMPLE OUTPUT 7.6: WORKING WITH SINGLE QUOTES IN BOURNE SHELLS Another way of making reference to variables inside other variables is through the use of double quotes. In addition, double quotes can include single quotes in it. 3 tiger% set MYNAME = "Ioannis" 4 tiger% set HELLO = "Hello $MYNAME" 5 tiger% echo $HELLO Hello Ioannis 6 tiger% echo "Hello 'nice' world" Hello 'nice' world 7 tiger% SAMPLE OUTPUT 7.7: WORKING WITH SINGLE QUOTES IN BOURNE SHELLS In the example provided (7.7), we defined a variable MYNAME with value Ioannis, then we defined an additional variable called HELLO using double quotes. In this variable, during the assignment process, we used the former variable as a part of former variable. The echo command resulted in the expected outcome which corresponds to the string Hello Ioannis. Moreover, we also demonstrated the use of single quotes into double quotes. In fact, these were interpreted as regular symbols as the interpreter ignored any special meaning of them. The use of back quotes is quite different. More precisely, there are several times we need to assign into variables values that are obtained by the execution of a command or a pipeline. This is achieved by the use of back quotes. Assuming that we need to define a variable called YEAR and assign into it the value obtained by the execution of a pipeline. The following combination of commands with the use of back quotes will result in the expected outcome. PAGE 5

6 27 tiger% set YEAR = `date cut -f6 -d' '` 28 tiger% echo $YEAR tiger% SAMPLE OUTPUT 7.7: WORKING WITH SINGLE QUOTES IN BOURNE SHELLS In order to define our variable, we used the well known command set. However, in order to dictate the execution of the pipeline, we placed it into back quotes. After pressing the <RETURN KEY>, csh executed the pipeline command; the output obtained was assigned to the variable YEAR. Moreover, in order to avoid the use of pipelines and obtain date s output that corresponds to the year value, we can also use the option + %Y. Any examples are omitted as this can be carried out easily. After understanding some basic notions about the use of backslash, single quotes, double quotes and back quotes, we are ready to move to the next section that introduces the notion of shells and some basic shell programming. 7.2 INTRODUCTION TO SHELLS There are several notions that have been presented so far. For instance, we considered UNIX commands, environment variables, processes, pipelines and so on. However, as the most important element is the shell, in this section we are going to introduce the components that consist of shells which make it to be a programming language itself. The functionality of the shell can be considered as multi-dimensional. Commands, we have learnt so far can be executed because they can be found in directories included in our PATH variable. These commands allow us to runs programs such as the VI editor, to construct shell scripts, to store files and so on. Moreover, through the use of the shell we can have access to development environments and programming languages that allow us to develop various programs and applications. In addition, through the shell we can interact with the UNIX kernel, check the success or failure of commands PAGE 6

7 (i.e. standard output, standard error), check the state of the file system, obtained and set up values assigned to environment variables. However, the shell is also a programming language itself which is specifically designed for use with the UNIX operating system. Through the use of commands, it allows us to gather information from the kernel and write shell scripts that can process this information and perform various tasks. In fact, this also allows us to develop our commands. Note that although the shell can be considered as a very expressive programming language, it is not recommended for the development of various applications with scope out of the UNIX environment SHELL SYNTAX Each programming language consists of a set of primitive components such as its alphabet and its syntax. The alphabet is a set of symbols that are used by this language while its syntax corresponds to formation rules that define how these symbols can be bound together. Alternatively, these rules determine what is allowed to write and what it is forbidden. Typically, programs written using these constructs are known as scripts. In short, these are files containing lines of commands that can be interpreted by the shell interpreter. Scripts can be simple consisting of few lines or can be more complex with hundreds of lines in them. Simple scripts may be easy understandable but those that consists of several or even hundred of lines may not be easily understood. Therefore, we need to follow some simple rules that can facilitate us and other people who may need to work on these scripts. At the top of the script, we provide information about: the name of the script and a short description about its use; the author of the script; when it was written; any comments related to it i.e. version number etc. A typical example of a script is described in the following sample. PAGE 7

8 # ************************************************** # Timestamp # This script redirects output into a file called timestamp. # It obtains a list of all users who are logged in a machine # There are two option available. The first given information about # users, terminals and dates. Option two gives a list of users Internet # connection. # Developed by Ioannis Svigkos # # Version 1.0 # Comments: It makes use of LOGNAME environment # variable. # ************************************************** SAMPLE OUTPUT 7.8: A TYPICAL SCRIPT STRUCTURE (1) Moreover, we need to provide information about each part of the script. This is achieved by the use of comments expressed by the hash (#) symbol. In fact, everything that is written after # will be ignored by the shell interpreter. Consider for example, the following script: echo "Please select one of the following options:" # echoes a message echo "Press one (1) for login identifiers, terminal and date info" # echoes echo "Press two (2) for Internet connections only" # echos 2nd choice set choice = $< # prompts for user input set choice = "f$choice" # changes choice to include letter f echo "Time stamping starts... you selected option $choice" # echoes (who cut -$choice -d' ') > stamp # performs operations echo "Time stamp successfully finished." # echoes operation ends echo " " # blank line echo "The results are stored in file stamp and are..." # echoes more stamp # displays contents of file stamp on standard output echo SAMPLE OUTPUT 7.9: A TYPICAL SCRIPT STRUCTURE (2) This script includes several echo commands that display some information to our terminal windows after its execution. Although, it is a very simple example, we can see that this script prompts the user to select one of two choices presented. Then it stores this information into a file called stamp. The most important points here are that when this script is executed, users are PAGE 8

9 prompted to enter data. This is achieved by the use of set choice = $< that prompts for user input. Moreover, each line has a comment that explains its use. Further description of this script is omitted as there is a detailed description in the comments provided for each line FORMATTING OUTPUT In order to printout a string on our terminal window, so far we have considered the echo command. However, echo exhibits some limitations. For instance, it can print only one line on screen. A possible solution to this problem may be the use of multiple echo commands. However, this is not very efficient. An alternative is the use of printf command which allows the formatting of an output. This is carried out by giving the string as an argument while in the context of this string we can include some special formatting characters. These characters can be found on table 7.1. CHARACTER DESCRIPTION \a Bell \b Backspace \f Skips one page if this is possible \n New line \r Carriage return \t Tab \v Vertical tab \\ \ %d Integer decimal %o Integer octal %x Integer Hexadecimal %s String %c Character TABLE 7.1: PRINTF FORMATTING CHARACTERS The following sample output describes some common use of the printf command. PAGE 9

10 tiger% printf "Hello. How are you?" Hello. How are you?3 tiger% printf "Hello!\nHow are you?\n" Hello! How are you? 5 tiger% printf "\a" 6 tiger% printf "Hello\tHow are you?" Hello How are you?7 tiger% printf "Hello\t How are you? \n" Hello How are you? SAMPLE OUTPUT 7.10: WORKING WITH PRINTF When, we entered the command printf Hello. How are you?, we avoided putting any control tags in it. The consequence was that the string was printed but our command line was placed at the same line. This is due to the fact that we did not enter the control tag \n that indicates new line should be included there. This was resolved after the inclusion of the corresponding control tag. Next, we used prinf \a and indeed we heard a beep. \t printed the corresponding string and separated Hello from How are you? with a tab between them. Finally, we demonstrated that various control tags can be inserted in a sentence. 8 tiger% printf "Hello %s \n" "Ioannis" Hello Ioannis 9 tiger% printf "Welcome back %s \n. Your account balance is %d OD" "Tom" 50 Welcome back Tom. Your account balance is 50 OD 10 tiger% SAMPLE OUTPUT 7.11: WORKING WITH PRINTF In sample output 7.11 we describe some conversion characters that instruct how a part of an argument given (string) should be displayed. Note that the number of conversion characters, included in a string, should be equal to the number of arguments given excluding the first argument which is the script itself. For example, in printf Hello %s\n Ioannis the conversion character %s informs the shell that a string given as an argument will follow. Indeed the string is Ioannis. "Welcome back %s \n. Your account balance is %d OD" "Tom" 50 command contains two conversion characters and one control tag. The conversion characters are %s that represents a string PAGE 10

11 and %d that corresponds to an integer number. The arguments given for these conversion characters are: Tom and 50, respectively. The \n just instructed the shell to print Your account balance is %d OD to a new line. printf can also be used with environment variables. Note that conversion characters can be used to represent environment variables, as well. 6 tiger% printf "Hello $LOGNAME\n" Hello svigkoi 7 tiger% printf "Hello %s\n" $LOGNAME Hello svigkoi 8 tiger% SAMPLE OUTPUT 7.11: WORKING WITH PRINTF In the above sample output, we initially executed a printf command which has as argument a string and an environment variable both included in quotes. In the second example provided, we used a conversion character while we gave the environment variable as an additional argument. Both examples output exactly the same results OBTAINING USER INPUT When writing scripts, we may need to obtain some user input. This is accomplished by the use of the set command. However, the way we use it in order to achieve our goal is quite different than the usual one. More precisely we need to use something like that set myvar = $<. 25 tiger% csh input Please enter your first name.ioannis Please enter your surname.svigkos Hello Ioannis Svigkos! How are you? SAMPLE OUTPUT 7.11: WORKING WITH PRINTF This instructs the shell to prompt for user input. In sample output 7.9 and 7.11, there are some indicative examples. Note that as syntax in Bourne shells differs, prompting for user input is carried out by the use of the read command. PAGE 11

12 7.2.4 PASSING INPUT AS A SCRIPT ARGUMENT The previous section demonstrated how to enter values into our scripts. Moreover, so far, we have also learnt how to use environment variables in our scripts. Both of these ways allow us to use data in our scripts. However, we may need to pass data as arguments during the initialisation of our script. In fact, a script can be considered as a command that can be executed and it may need to have some arguments. The method of defining arguments is through the use of $<number>. For example, $1 represents our first argument while $2 is the second argument and so on. These specialised variables are known as positional parameters and can be used as regular variables. However, note that they cannot be reset by using the command unset or by using set =. 2 tiger% cat > arguments $1 $2 $3 echo "This is the first argument $1" echo "This is the second argument $2" echo "This is the third argument $3" 3 tiger% csh arguments One Two Three One: Command not found This is the first argument One This is the second argument Two This is the third argument Three 4 tiger% SAMPLE OUTPUT 7.12: PASSING DATA AS SCRIPT ARGUMENTS As shown, we defined three positional parameters $1, $2, $3 in our script called argument that echoes each of them. We executed the script by giving the values One Two Three, respectively. The output is given in sample Note that we can use as many positional parameters we wish but there are some that have a special meaning. These are $0 that represents the name of the script and $#argv that corresponds to the number of positional parameters given. Whilst $argv[*] represents a word list of any parameters given excluding the name of the script. PAGE 12

13 16 tiger% more arguments $1 $2 $3 echo "This is the first argument $1" echo "This is the second argument $2" echo "This is the third argument $3" echo "*************************************" echo "SCRIPT'S NAME: $0" echo "POSSITIONAL PARAMETERS: $#argv" echo WORD LIST PARAMETERS: $argv[*] 17 tiger% csh arguments : Command not found This is the first argument 1 This is the second argument 2 This is the third argument 3 ************************************* SCRIPT'S NAME: arguments POSSITIONAL PARAMETERS: 3 WORD LIST PARAMETERS: tiger% SAMPLE OUTPUT 7.13: PASSING DATA AS SCRIPT ARGUMENTS This sample output demonstrated the use of some specific positional parameters. The upper half of this sample describes the script we developed while the lower half part corresponds to the output given after the execution of the script EXIT STATUS Anytime we perform a UNIX command, the command is executed by the shell and any results are typically displayed on our terminal window. These results may include something obtained through the standard output or they may be error messages directed to the standard error. However, the problem here is that machines cannot interpret any sentences given as output and understand the meaning of an error message. Therefore, the success of failure of each UNIX command should be represented by an integer In fact, every time we execute a command, its termination returns a number known as exit status. Typically, the success of each command is denoted by the integer zero (0) while any failures return number (1). In order to find out the exit status of the last command executed we need to access the PAGE 13

14 contents of an environment variable known as status. This is applicable to C shells. In Bourne shells, we simply need to type in our command prompt $?. 12 tiger% date Mon May 30 02:06:06 BST tiger% echo $status 0 14 tiger% acommand acommand: Command not found. 15 tiger% echo $status 1 16 tiger% ls -l file -rwx svigkoi staff 6 May 30 02:20 file 17 tiger% chmod 500 file 18 tiger% ls l file -r-x svigkoi staff 6 May 30 02:20 file 19 tiger% cat >> file file: Permission denied 20 tiger% echo $status 1 21 tiger% SAMPLE OUTPUT 7.10: EXIT STATUS We initially typed date which was executed successfully by displaying the date and time on our terminal window. Next, we echoed the contents of variable status. This displayed number 0 and it was expected as the execution of date was successful. Next, we typed command acommand which could not be found in the environment path. Therefore, an error message was returned. In an attempt to see the contents of variable status, we saw now its value is set to number 1. In addition, we also attempted to write information into a writeprotected file. Again, we received an error message while the status variable was set to number 1 which indicated there was an error LIST COMMANDS In order to understand the use of exit status, we can consider the use of list commands. These are commands that consist of simple UNIX commands or can be composed of by pipelines separated by or &&. The use of the former symbol refers to an or-list while the use of the latter one refers to an and-list. PAGE 14

15 OR-list: A typical example is pipelinea pipelineb This means that if pipelinea starts its execution and returns a non-zero exit status then pipelineb will start its execution. If pipelinea returns zero, pipelineb will never be executed. Moreover, the return status of this list will be 0, if pipelinea will be executed successfully or it will have a return status that stems from the execution of pipelineb which can be zero or non-zero. If non-zero is the outcome then this means that Or-list exited with an error. AND-list: An example is pipelinea && pipelineb When pipelinea is run if after its execution returns a zero exit status, pipelineb is run. The exit status of an and-list corresponds to pipelinea if zero. However, if pipelinea or pipelineb returns a non-zero exit status then the exit status of the pipeline corresponds to the exit status of the pipeline which returns the non-zero exit status. In general, an and-list succeeds if and only if both pipelines will be executed successfully. 2 tiger% who cut -f1 -d' ' echo "Command failed" w w getovv beusdul w svigkoi w w w w dowling xanthisl w tiger% echo $status 0 4 tiger% who cat -f1 -d' ' echo "Command failed" cat: illegal option -- f usage: cat [ -usvtebn ] [- file]... Command failed 5 tiger% echo $status 6 tiger% 1 7 tiger% SAMPLE OUTPUT 7.11: OR-LIST PAGE 15

16 After entering the or-list command who cut -f1 -d' ' echo "Command failed" and pressing the <Return> key, it was executed successfully. In fact, in our terminal display we could see a list of all users logged in tiger.westminster.ac.uk. As, the pipeline who cut f1 d returned exit status 0, the echo command was not executed. The exit status of or-list was 0, as well. We attempted to execute who cat -f1 -d' ' echo "Command failed" but because of a syntax error, the UNIX shell could not execute the pipeline on the left hand side. Therefore, the command echo Command Failed was executed informing us about this event. Of course, the exit status of the or-list was expected to be 1 indicating this error. Considering and-lists, we provide a similar example that will allow us to understand any differences between this command and the previously elaborated or-list command. 7 tiger% who cut -f1 -d' ' && echo "Both succeeded, thus and-list succeeded" w w getovv beusdul w svigkoi w w w w dowling xanthisl w Both succeeded, thus and-list succeeded 8 tiger% echo $status 0 9 tiger% who cat -f1 -d' ' && echo "Impossible to succeed" cat: illegal option -- f usage: cat [ -usvtebn ] [- file] tiger% echo $status 1 11 tiger% SAMPLE OUTPUT 7.12: OR-LIST PAGE 16

17 The execution of who cut -f1 -d' ' && echo "Both succeeded, thus and-list succeeded" add-list was successful. Therefore, both commands placed on the left hand and right hand side were executed. The exit status of this and-list was 0 which corresponds to successful execution. An attempt to execute who cat -f1 -d' ' && echo "Impossible to succeed had the expected outcome. The pipeline on the left hand side failed and returned exit status 1. Thus, the execution of this and-list was terminated and returns exit status equal to 1. Here, the general rule regarding or-lists is that if the first pipeline fails then the second will start running. The success of an or-list is guaranteed if one of the or-list parts is executed successfully. If both fail then the list fails. On contrast with or-lists, the rule for add-lists reflects that if one part fails then and-list fails. If both succeed then and-list succeeds. 7.3 ARITHMETIC OPERATIONS Being in front of our terminal window, we may sometimes need a calculator in order to perform some calculations. Moreover, when we develop scripts, we may need to perform various calculations in our scripts and display any results on a terminal window or store them into a file. The utility that is used in these cases in known as bc (basic calculator). Although, bc can perform some complex calculations in bases other than 10, in this section we concentrate in some basic calculations in base tiger% bc 10 * 2 20 scale = / * ^2 4 sqrt(800) tiger% SAMPLE OUTPUT 7.13: USING BC PAGE 17

18 As most of operations demonstrated are self explanatory, we omit any description. However, sqrt() is just a predefined function that calculates the square root of a given argument while scale = 6 reflects that any subsequent calculations should be displayed with 5 decimal numbers. OPERATION DESCRIPTION + Addition - Subtraction * Multiplication / Division % Integer remainder ^ Power sqrt Square root scale Scale length Number of decimal digits TABLE 7.2: OPERATORS AND FUNCTIONS IN BC Note that, we can also use parentheses, if we wish to perform more complex calculations. However, there are some rules i.e. multiplication and division take precedence over addition and subtraction. Moreover, we can use create pipelines using the bc utility. 30 tiger% bc 2 * * * (10 + (2*4)) tiger% echo "3 + 3" bc 6 34 tiger% echo "sqrt(9)" bc 3 35 tiger% SAMPLE OUTPUT 7.14: OPERATOR PRECEDENCE AND PIPELINING UNING BC The calculation of 2 * 10 2 gave us 18. This is correct as bc calculated first the multiplication part and then performed the subtraction. Similarly, bc performed the other operations entered according to some precedence over operators and parentheses. PAGE 18

19 7.4 EXERCISES 1. Create a directory called scripts. a. Change directory by moving into scripts. b. Execute an echo command with argument Hello & Have a nice day c. Did this command display the expected Hello & Have a nice day d. If NO, then use an appropriate character to override the functionality of &. 2. Repeat exercise one and instead of & symbol use the character >. Try to understand the output given by this command. After that use single quotes and try to understand the difference. 3. Define a variable called MYNAME and assign into it your name. a. Write a script called welcome that gives a similar output: Hello TOM. Your current directory is: /usr/eland/staff/user1/tom You can start working. NOTE: USE COMMAND PRINTF INSTEAD OF ECHO b. Execute this script. 4. Using back quotes define a variable MYWORKINGDIR and assign into it a value that corresponds to your current directory. [HINT: make use of pwd command] 5. Develop a script called myls that accepts one argument. This argument corresponds to the absolute path of a directory. The output of the script should be similar to: Script name: myls [USE $0 TO DISPLAY THE NAME OF THE SCRIPT] Absolute path: /user/eland/staff/user1/tome/scripts PAGE 19

20 The contents of this directory are: myfile1 myfile2 myfile3 [MAKE USE OF LS OR LS L COMMAND]] 6. Develop a script called calc that accepts three arguments (integers) and multiplies them. The output of the script should be similar to: Script name: Argument one: Argument two: Argument three: Performing multiplication The result is: ($1 * $2 * $3) =. 7. In scripts directory create two text files using the VI editor with names f1 and f2 with contents: [f1 Contents] This is my first file [f2 contents] This is my second file a. Write a list command that compares (diff) the two files. If f1 and f2 are different then the first file should be sent to yourself. [HINT: MAKE USE OF AN OR-LIST COMMAND, DIFF COMMAND AND MAILX COMMAND] b. Create a file called f3 with identical contents of file f1. Compare both files and if they are identical delete file f1. [HINT: MAKE USE OF AN A-LIST COMMAND, CMP COMMAND AND RM COMMAND] 8. Execute command ls l and then check its exit status. Enter another command that is typed incorrectly and then check its exit status. PAGE 20

21 9. Develop a script that accepts four arguments and using printf display its arguments as a word list. Make sure your script also displays the name of the script and the number of arguments given. PAGE 21

S E C T I O N O V E R V I E W

S E C T I O N O V E R V I E W PROGRAM CONTROL, FILE ARCHIVING, ENVIRONMENT AND SCRIPTS S E C T I O N O V E R V I E W Continuing from last section, we are going to learn about the following concepts: controlling programs; working with

More information

S E C T I O N O V E R V I E W

S E C T I O N O V E R V I E W INPUT, OUTPUT REDIRECTION, PIPING AND PROCESS CONTROL S E C T I O N O V E R V I E W In this section, we will learn about: input redirection; output redirection; piping; process control; 5.1 INPUT AND OUTPUT

More information

CMPS 12A Introduction to Programming Lab Assignment 7

CMPS 12A Introduction to Programming Lab Assignment 7 CMPS 12A Introduction to Programming Lab Assignment 7 In this assignment you will write a bash script that interacts with the user and does some simple calculations, emulating the functionality of programming

More information

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers A Big Step Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Copyright 2006 2009 Stewart Weiss What a shell really does Here is the scoop on shells. A shell is a program

More information

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Scripting Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers Adapted from Practical Unix and Programming Hunter College Copyright 2006 2009 Stewart Weiss What a shell

More information

S E C T I O N O V E R V I E W

S E C T I O N O V E R V I E W FILES AND DIRECTORIES: ADVANCED CONCEPTS S E C T I O N O V E R V I E W In this section, we will learn about: understanding soft (symbolic) links; understanding hard links; working with soft and hard links;

More information

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs Summer 2010 Department of Computer Science and Engineering York University Toronto June 29, 2010 1 / 36 Table of contents 1 2 3 4 2 / 36 Our goal Our goal is to see how we can use Unix as a tool for developing

More information

12.1 UNDERSTANDING UNIX SHELL PROGRAMMING LANGUAGE: AN INTRODUCTION Writing a Simple Script Executing a Script

12.1 UNDERSTANDING UNIX SHELL PROGRAMMING LANGUAGE: AN INTRODUCTION Writing a Simple Script Executing a Script 12 Shell Programming This chapter concentrates on shell programming. It explains the capabilities of the shell as an interpretive high-level language. It describes shell programming constructs and particulars.

More information

bash Data Administrative Shell Scripting COMP2101 Fall 2017

bash Data Administrative Shell Scripting COMP2101 Fall 2017 bash Data Administrative Shell Scripting COMP2101 Fall 2017 Variables Every process has memory-based storage to hold named data A named data item is referred to as a variable (sometimes called a parameter),

More information

UNIX shell scripting

UNIX shell scripting UNIX shell scripting EECS 2031 Summer 2014 Przemyslaw Pawluk June 17, 2014 What we will discuss today Introduction Control Structures User Input Homework Table of Contents Introduction Control Structures

More information

9.2 Linux Essentials Exam Objectives

9.2 Linux Essentials Exam Objectives 9.2 Linux Essentials Exam Objectives This chapter will cover the topics for the following Linux Essentials exam objectives: Topic 3: The Power of the Command Line (weight: 10) 3.3: Turning Commands into

More information

Bash scripting Tutorial. Hello World Bash Shell Script. Super User Programming & Scripting 22 March 2013

Bash scripting Tutorial. Hello World Bash Shell Script. Super User Programming & Scripting 22 March 2013 Bash scripting Tutorial Super User Programming & Scripting 22 March 2013 Hello World Bash Shell Script First you need to find out where is your bash interpreter located. Enter the following into your command

More information

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

More information

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines Introduction to UNIX Logging in Basic system architecture Getting help Intro to shell (tcsh) Basic UNIX File Maintenance Intro to emacs I/O Redirection Shell scripts Logging in most systems have graphical

More information

Bourne Shell Reference

Bourne Shell Reference > Linux Reviews > Beginners: Learn Linux > Bourne Shell Reference Bourne Shell Reference found at Br. David Carlson, O.S.B. pages, cis.stvincent.edu/carlsond/cs330/unix/bshellref - Converted to txt2tags

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash CS 25200: Systems Programming Lecture 10: Shell Scripting in Bash Dr. Jef Turkstra 2018 Dr. Jeffrey A. Turkstra 1 Lecture 10 Getting started with Bash Data types Reading and writing Control loops Decision

More information

ITST Searching, Extracting & Archiving Data

ITST Searching, Extracting & Archiving Data ITST 1136 - Searching, Extracting & Archiving Data Name: Step 1 Sign into a Pi UN = pi PW = raspberry Step 2 - Grep - One of the most useful and versatile commands in a Linux terminal environment is the

More information

5/20/2007. Touring Essential Programs

5/20/2007. Touring Essential Programs Touring Essential Programs Employing fundamental utilities. Managing input and output. Using special characters in the command-line. Managing user environment. Surveying elements of a functioning system.

More information

1. Hello World Bash Shell Script. Last Updated on Wednesday, 13 April :03

1. Hello World Bash Shell Script. Last Updated on Wednesday, 13 April :03 1 of 18 21/10/2554 9:39 Bash scripting Tutorial tar -czf myhome_directory.tar.gz /home/linuxcong Last Updated on Wednesday, 13 April 2011 08:03 Article Index 1. Hello World Bash Shell Script 2. Simple

More information

Exploring UNIX: Session 3

Exploring UNIX: Session 3 Exploring UNIX: Session 3 UNIX file system permissions UNIX is a multi user operating system. This means several users can be logged in simultaneously. For obvious reasons UNIX makes sure users cannot

More information

UNIX files searching, and other interrogation techniques

UNIX files searching, and other interrogation techniques UNIX files searching, and other interrogation techniques Ways to examine the contents of files. How to find files when you don't know how their exact location. Ways of searching files for text patterns.

More information

The Online Unix Manual

The Online Unix Manual ACS-294-001 Unix (Winter Term, 2018-2019) Page 14 The Online Unix Manual Unix comes with a large, built-in manual that is accessible at any time from your terminal. The Online Manual is a collection of

More information

Section 5.5: Text Menu Input from Character Strings

Section 5.5: Text Menu Input from Character Strings Chapter 5. Text User Interface TGrid user interface also consists of a textual command line reference. The text user interface (TUI) is written in a dialect of Lisp called Scheme. Users familiar with Scheme

More information

A shell can be used in one of two ways:

A shell can be used in one of two ways: Shell Scripting 1 A shell can be used in one of two ways: A command interpreter, used interactively A programming language, to write shell scripts (your own custom commands) 2 If we have a set of commands

More information

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt ULI101 Week 03 Week Overview Absolute and relative pathnames File name expansion Shell basics Command execution in detail Recalling and editing previous commands Quoting Pathnames A pathname is a list

More information

A Brief Introduction to the Linux Shell for Data Science

A Brief Introduction to the Linux Shell for Data Science A Brief Introduction to the Linux Shell for Data Science Aris Anagnostopoulos 1 Introduction Here we will see a brief introduction of the Linux command line or shell as it is called. Linux is a Unix-like

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

Unix Introduction to UNIX

Unix Introduction to UNIX Unix Introduction to UNIX Get Started Introduction The UNIX operating system Set of programs that act as a link between the computer and the user. Developed in 1969 by a group of AT&T employees Various

More information

Essential Unix (and Linux) for the Oracle DBA. Revision no.: PPT/2K403/02

Essential Unix (and Linux) for the Oracle DBA. Revision no.: PPT/2K403/02 Essential Unix (and Linux) for the Oracle DBA Revision no.: PPT/2K403/02 Architecture of UNIX Systems 2 UNIX System Structure 3 Operating system interacts directly with Hardware Provides common services

More information

Basics. I think that the later is better.

Basics.  I think that the later is better. Basics Before we take up shell scripting, let s review some of the basic features and syntax of the shell, specifically the major shells in the sh lineage. Command Editing If you like vi, put your shell

More information

C Shell Tutorial. Section 1

C Shell Tutorial. Section 1 C Shell Tutorial Goals: Section 1 Learn how to write a simple shell script and how to run it. Learn how to use local and global variables. About CSH The Barkley Unix C shell was originally written with

More information

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1 Shell Scripting Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 If we have a set of commands that we want to run on a regular basis, we could write a script A script acts as a Linux command,

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples EECS2301 Title Unix/Linux Introduction These slides are based on slides by Prof. Wolfgang Stuerzlinger at York University Warning: These notes are not complete, it is a Skelton that will be modified/add-to

More information

Linux File System and Basic Commands

Linux File System and Basic Commands Linux File System and Basic Commands 0.1 Files, directories, and pwd The GNU/Linux operating system is much different from your typical Microsoft Windows PC, and probably looks different from Apple OS

More information

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT Unix as a Platform Exercises Course Code: OS-01-UNXPLAT Working with Unix 1. Use the on-line manual page to determine the option for cat, which causes nonprintable characters to be displayed. Run the command

More information

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017 Linux Shell Scripting Linux System Administration COMP2018 Summer 2017 What is Scripting? Commands can be given to a computer by entering them into a command interpreter program, commonly called a shell

More information

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu) I. INTERACTIVE MODE VERSUS SCRIPT MODE There are two ways to use the python interpreter: interactive mode and script mode. 1. Interactive Mode (a) open a terminal shell (terminal emulator in Applications

More information

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science CSCI 211 UNIX Lab Shell Programming Dr. Jiang Li Why Shell Scripting Saves a lot of typing A shell script can run many commands at once A shell script can repeatedly run commands Help avoid mistakes Once

More information

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

Fundamentals: Expressions and Assignment

Fundamentals: Expressions and Assignment Fundamentals: Expressions and Assignment A typical Python program is made up of one or more statements, which are executed, or run, by a Python console (also known as a shell) for their side effects e.g,

More information

Title:[ Variables Comparison Operators If Else Statements ]

Title:[ Variables Comparison Operators If Else Statements ] [Color Codes] Environmental Variables: PATH What is path? PATH=$PATH:/MyFolder/YourStuff?Scripts ENV HOME PWD SHELL PS1 EDITOR Showing default text editor #!/bin/bash a=375 hello=$a #No space permitted

More information

Introduction: What is Unix?

Introduction: What is Unix? Introduction Introduction: What is Unix? An operating system Developed at AT&T Bell Labs in the 1960 s Command Line Interpreter GUIs (Window systems) are now available Introduction: Unix vs. Linux Unix

More information

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9

More information

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2) BANK ON & SHELL PROGRAMMING-502 (CORE PAPER-2) TOPIC 1: VI-EDITOR MARKS YEAR 1. Explain set command of vi editor 2 2011oct 2. Explain the modes of vi editor. 7 2013mar/ 2013 oct 3. Explain vi editor 5

More information

Topic 2: More Shell Skills

Topic 2: More Shell Skills Topic 2: More Shell Skills Sub-topics: 1 quoting 2 shell variables 3 sub-shells 4 simple shell scripts (no ifs or loops yet) 5 bash initialization files 6 I/O redirection & pipes 7 aliases 8 text file

More information

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT Unix as a Platform Exercises + Solutions Course Code: OS 01 UNXPLAT Working with Unix Most if not all of these will require some investigation in the man pages. That's the idea, to get them used to looking

More information

LESSON 4. The DATA TYPE char

LESSON 4. The DATA TYPE char LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze EECS 2031 Software Tools Prof. Mokhtar Aboelaze Footer Text 1 EECS 2031E Instructor: Mokhtar Aboelaze Room 2026 CSEB lastname@cse.yorku.ca x40607 Office hours TTH 12:00-3:00 or by appointment 1 Grading

More information

Introduction to Bash Programming. Dr. Xiaolan Zhang Spring 2013 Dept. of Computer & Information Sciences Fordham University

Introduction to Bash Programming. Dr. Xiaolan Zhang Spring 2013 Dept. of Computer & Information Sciences Fordham University Introduction to Bash Programming Dr. Xiaolan Zhang Spring 2013 Dept. of Computer & Information Sciences Fordham University 1 Outline Shell command line syntax Shell builtin commands Shell variables, arguments

More information

Using echo command in shell script

Using echo command in shell script Lab 4a Shell Script Lab 2 Using echo command in shell script Objective Upon completion of this lab, the student will be able to use echo command in the shell script. Scenario The student is the administrator

More information

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Fundamentals of Programming. Lecture 3: Introduction to C Programming Fundamentals of Programming Lecture 3: Introduction to C Programming Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department Outline A Simple C

More information

Chapter 2, Part I Introduction to C Programming

Chapter 2, Part I Introduction to C Programming Chapter 2, Part I Introduction to C Programming C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 2016 Pearson Education, Ltd. All rights reserved. 2 2016 Pearson Education,

More information

Linux & Shell Programming 2014

Linux & Shell Programming 2014 Practical No : 1 Enrollment No: Group : A Practical Problem Write a date command to display date in following format: (Consider current date as 4 th January 2014) 1. dd/mm/yy hh:mm:ss 2. Today's date is:

More information

Sub-Topic 1: Quoting. Topic 2: More Shell Skills. Sub-Topic 2: Shell Variables. Referring to Shell Variables: More

Sub-Topic 1: Quoting. Topic 2: More Shell Skills. Sub-Topic 2: Shell Variables. Referring to Shell Variables: More Topic 2: More Shell Skills Plan: about 3 lectures on this topic Sub-topics: 1 quoting 2 shell variables 3 sub-shells 4 simple shell scripts (no ifs or loops yet) 5 bash initialization files 6 I/O redirection

More information

Topic 2: More Shell Skills. Sub-Topic 1: Quoting. Sub-Topic 2: Shell Variables. Difference Between Single & Double Quotes

Topic 2: More Shell Skills. Sub-Topic 1: Quoting. Sub-Topic 2: Shell Variables. Difference Between Single & Double Quotes Topic 2: More Shell Skills Sub-Topic 1: Quoting Sub-topics: 1 quoting 2 shell variables 3 sub-shells 4 simple shell scripts (no ifs or loops yet) 5 bash initialization files 6 I/O redirection & pipes 7

More information

CS/CIS 249 SP18 - Intro to Information Security

CS/CIS 249 SP18 - Intro to Information Security Lab assignment CS/CIS 249 SP18 - Intro to Information Security Lab #2 - UNIX/Linux Access Controls, version 1.2 A typed document is required for this assignment. You must type the questions and your responses

More information

Unix Shell scripting. Dr Alun Moon 7th October Introduction. Notation. Spaces

Unix Shell scripting. Dr Alun Moon 7th October Introduction. Notation. Spaces Unix Shell scripting Dr Alun Moon 7th October 2017 Introduction Shell scripts in Unix are a very powerfull tool, they form much of the standard system as installed. What are these good for? So many file

More information

Introduction to Programming in Turing. Input, Output, and Variables

Introduction to Programming in Turing. Input, Output, and Variables Introduction to Programming in Turing Input, Output, and Variables The IPO Model The most basic model for a computer system is the Input-Processing-Output (IPO) Model. In order to interact with the computer

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University Unix/Linux Basics 1 Some basics to remember Everything is case sensitive Eg., you can have two different files of the same name but different case in the same folder Console-driven (same as terminal )

More information

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output

More information

System Programming. Session 6 Shell Scripting

System Programming. Session 6 Shell Scripting System Programming Session 6 Shell Scripting Programming C Programming vs Shell Programming C vs Shell Programming Compilation/Direct execution C Requires compilation while shell script can be directly

More information

Continue reading command lines even after an execution error has caused the abandonment of aline.

Continue reading command lines even after an execution error has caused the abandonment of aline. NAME calc arbitrary precision calculator SYNOPSIS calc [ c] [ C] [ d] [-D calc_debug[:resource_debug[:user_debug]]] [ e] [ h] [ i] [ m mode] [ O] [ p] [ q] [ s] [ u] [ v] [calc_cmd...] #!c:/progra 1/Calc/bin/calc

More information

B a s h s c r i p t i n g

B a s h s c r i p t i n g 8 Bash Scripting Any self-respecting hacker must be able to write scripts. For that matter, any selfrespecting Linux administrator must be able to script. Hackers often need to automate commands, sometimes

More information

Script Programming Systems Skills in C and Unix

Script Programming Systems Skills in C and Unix Script Programming with Perl II 15-123 Systems Skills in C and Unix Subroutines sub sum { return $a + $b; } So we can call this as: $a = 12; $b = 10; $sum = sum(); print the sum is $sum\n ; Passing Arguments

More information

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 Bashed One Too Many Times Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 What is a Shell? The shell interprets commands and executes them It provides you with an environment

More information

File Commands. Objectives

File Commands. Objectives File Commands Chapter 2 SYS-ED/Computer Education Techniques, Inc. 2: 1 Objectives You will learn: Purpose and function of file commands. Interrelated usage of commands. SYS-ED/Computer Education Techniques,

More information

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved AICT High Performance Computing Workshop With Applications to HPC Edmund Sumbar research.support@ualberta.ca Copyright 2007 University of Alberta. All rights reserved High performance computing environment

More information

COMS 6100 Class Notes 3

COMS 6100 Class Notes 3 COMS 6100 Class Notes 3 Daniel Solus September 1, 2016 1 General Remarks The class was split into two main sections. We finished our introduction to Linux commands by reviewing Linux commands I and II

More information

Outline. Structure of a UNIX command

Outline. Structure of a UNIX command Outline Structure of Unix Commands Command help (man) Log on (terminal vs. graphical) System information (utility) File and directory structure (path) Permission (owner, group, rwx) File and directory

More information

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group. CMPS 12L Introduction to Programming Lab Assignment 2 We have three goals in this assignment: to learn about file permissions in Unix, to get a basic introduction to the Andrew File System and it s directory

More information

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

More information

Work relative to other classes

Work relative to other classes Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language

More information

Vi & Shell Scripting

Vi & Shell Scripting Vi & Shell Scripting Comp-206 : Introduction to Week 3 Joseph Vybihal Computer Science McGill University Announcements Sina Meraji's office hours Trottier 3rd floor open area Tuesday 1:30 2:30 PM Thursday

More information

find Command as Admin Security Tool

find Command as Admin Security Tool find Command as Admin Security Tool Dr. Bill Mihajlovic INCS-620 Operating Systems Security find Command find command searches for the file or files that meet certain condition. like: Certain name Certain

More information

EC121 Mathematical Techniques A Revision Notes

EC121 Mathematical Techniques A Revision Notes EC Mathematical Techniques A Revision Notes EC Mathematical Techniques A Revision Notes Mathematical Techniques A begins with two weeks of intensive revision of basic arithmetic and algebra, to the level

More information

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu) I. INTERACTIVE MODE VERSUS SCRIPT MODE There are two ways to use the python interpreter: interactive mode and script mode. 1. Interactive Mode (a) open a terminal shell (terminal emulator in Applications

More information

I/O and Shell Scripting

I/O and Shell Scripting I/O and Shell Scripting File Descriptors Redirecting Standard Error Shell Scripts Making a Shell Script Executable Specifying Which Shell Will Run a Script Comments in Shell Scripts File Descriptors Resources

More information

Introduction to Linux

Introduction to Linux Introduction to Linux The command-line interface A command-line interface (CLI) is a type of interface, that is, a way to interact with a computer. Window systems, punched cards or a bunch of dials, buttons

More information

Chapter 2. Lexical Elements & Operators

Chapter 2. Lexical Elements & Operators Chapter 2. Lexical Elements & Operators Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr The C System

More information

CHAPTER 3 SHELL PROGRAMS: SCRIPTS

CHAPTER 3 SHELL PROGRAMS: SCRIPTS CHAPTER 3 SHELL PROGRAMS: SCRIPTS Any series of commands may be stored inside a regular text file for later execution. A file that contains shell commands is called a script. Before you can run a script,

More information

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University Introduction to Linux Woo-Yeong Jeong (wooyeong@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu What is Linux? A Unix-like operating system of a computer What is an

More information

Scripting Languages Course 1. Diana Trandabăț

Scripting Languages Course 1. Diana Trandabăț Scripting Languages Course 1 Diana Trandabăț Master in Computational Linguistics - 1 st year 2017-2018 Today s lecture Introduction to scripting languages What is a script? What is a scripting language

More information

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley PHP and MySQL for Dynamic Web Sites Intro Ed Crowley Class Preparation If you haven t already, download the sample scripts from: http://www.larryullman.com/books/phpand-mysql-for-dynamic-web-sitesvisual-quickpro-guide-4thedition/#downloads

More information

Starting. Read: Chapter 1, Appendix B from textbook.

Starting. Read: Chapter 1, Appendix B from textbook. Read: Chapter 1, Appendix B from textbook. Starting There are two ways to run your Python program using the interpreter 1 : from the command line or by using IDLE (which also comes with a text editor;

More information

Implementation of a simple shell, xssh

Implementation of a simple shell, xssh Implementation of a simple shell, xssh What is a shell? A process that does command line interpretation Reads a command from standard input (stdin) Executes command corresponding to input line In simple

More information

2) clear :- It clears the terminal screen. Syntax :- clear

2) clear :- It clears the terminal screen. Syntax :- clear 1) cal :- Displays a calendar Syntax:- cal [options] [ month ] [year] cal displays a simple calendar. If arguments are not specified, the current month is displayed. In addition to cal, the ncal command

More information

Getting to grips with Unix and the Linux family

Getting to grips with Unix and the Linux family Getting to grips with Unix and the Linux family David Chiappini, Giulio Pasqualetti, Tommaso Redaelli Torino, International Conference of Physics Students August 10, 2017 According to the booklet At this

More information

ACS Unix (Winter Term, ) Page 21

ACS Unix (Winter Term, ) Page 21 ACS-294-001 Unix (Winter Term, 2016-2017) Page 21 The Shell From the beginning, Unix was designed so that the shell is an actual program separated from the main part of the operating system. What is a

More information

The Unix Shell & Shell Scripts

The Unix Shell & Shell Scripts The Unix Shell & Shell Scripts You should do steps 1 to 7 before going to the lab. Use the Linux system you installed in the previous lab. In the lab do step 8, the TA may give you additional exercises

More information

Useful Unix Commands Cheat Sheet

Useful Unix Commands Cheat Sheet Useful Unix Commands Cheat Sheet The Chinese University of Hong Kong SIGSC Training (Fall 2016) FILE AND DIRECTORY pwd Return path to current directory. ls List directories and files here. ls dir List

More information

Lecture 02 The Shell and Shell Scripting

Lecture 02 The Shell and Shell Scripting Lecture 02 The Shell and Shell Scripting In this course, we need to be familiar with the "UNIX shell". We use it, whether bash, csh, tcsh, zsh, or other variants, to start and stop processes, control the

More information

Creating a Shell or Command Interperter Program CSCI411 Lab

Creating a Shell or Command Interperter Program CSCI411 Lab Creating a Shell or Command Interperter Program CSCI411 Lab Adapted from Linux Kernel Projects by Gary Nutt and Operating Systems by Tannenbaum Exercise Goal: You will learn how to write a LINUX shell

More information

CHAPTER 2 THE UNIX SHELLS

CHAPTER 2 THE UNIX SHELLS CHAPTER 2 THE UNIX SHELLS The layers in a UNIX system is shown in the following figure. system call interface library interface user interface Users Standard utility programs (shell, editors, compilers,

More information

Then, we modify the program list.1 to list two files.

Then, we modify the program list.1 to list two files. ACS-2941-001 Unix (Winter Term, 2016-17) Part II: Shell Programming Page 17 Working with Parameters A Unix shell allows users to pass parameters to shell scripts. With processing the parameters passed

More information

The Very Basics of the R Interpreter

The Very Basics of the R Interpreter Chapter 2 The Very Basics of the R Interpreter OK, the computer is fired up. We have R installed. It is time to get started. 1. Start R by double-clicking on the R desktop icon. 2. Alternatively, open

More information