Program Description You have a minor assignment coming up which asks that you work with the Bourne Again Shell (bash). This week we will be working with some of the concepts/techniques that you need to complete that minor assignment. For some of you, this may seem like a review. For others, this may be the first time that you've used a shell for anything other than basic commands. We will all get through this. The skills that you will demonstrate: Ability to write a bash script Demonstrate the effects of the three quoting mechanisms in bash In particular, demonstrate running a program and saving its output in a variable Demonstrate the use of loops and conditionals Background Wikipedia defines a shell as a "user interface for access to an operating system's services": We have seen the types of services that an operating system (OS) can provide. One of the main services is loading and executing programs, which you have all done. At the programming level, system calls are the interface for accessing OS services. The shell is a program which makes system calls for you. It specializes in loading and executing programs, but it can do much more. Behind the scenes, a shell will create the command-line arguments which your programs see. When you access the argc and argv variables (which you did in recitation 1) these values came from the shell. The exact values came either from the user (when they type commands) or another program. In either case, the shell will break command lines up into discrete words (stuff separated by spaces and tabs), and then create an argv array for the new program. The shell makes a couple of system calls to load and execute your program. Shell Variables One of the first new features that we will examine are shell variables. Like any programming language, the shell has variables. They are all strings, but strings can hold numbers too (like 12). The shell works with numeric values this way. There is a program call "expr" which will evaluate expressions using strings, but bash has built-in support for numeric operations on strings. Task Complete the following tasks. You may receive guidance from your instructor or other students. All code that you submit should be written by you. Write a shell script which reads text from the user into variables. Echo each word on a separate line. The shell will automatically tokenize convert to separate words) unquoted strings. Something like "for word in $string will split up $string into separate words. I would also like to see you running programs in subshells and capturing the output. This involves using the backquote (under - upper left of your keyboard). Strings in those quotes will be treated as command lines and run. The output of the command will be the value of the expression, so you can assign it to a variable. So, as a completely arbitrary task, for each file in the current directory, run "wc" to obtain the byte count for the file, and run "s" to get the size in kilobytes. Print both out for comparison. I don't care what the exact format is as long as the filename, byte count, and size in kilobytes is shown for each file. Hint: The shell's globbing feature" combined with a for loop would be a good choice for this assignment. Try out the following command: for a_file in echo "File Sa_file" done Again, for each file: Filename Size in Kilobytes Size in Bytes Turn in your program. Program Description You have a minor assignment coming up which asks that you work with the Bourne Again Shell (bash). This week we will be working with some of the concepts/techniques that you need to complete that minor assignment. For some of you, this may seem like a review. For others, this may be the first time that you've used a shell for anything other than basic commands. We will all get through this. The skills that you will demonstrate: Ability to write a bash script Demonstrate the effects of the three quoting mechanisms in bash In particular, demonstrate running a program and saving its output in a variable Demonstrate the use of loops and conditionals Background Wikipedia defines a shell as a "user interface for access to an operating system's services": We have seen the types of services that an operating system (OS) can provide. One of the main services is loading and executing programs, which you have all done. At the programming level, system calls are the interface for accessing OS services. The shell is a program which makes system calls for you. It specializes in loading and executing programs, but it can do much more. Behind the scenes, a shell will create the command-line arguments which your programs see. When you access the argc and argv variables (which you did in recitation 1) these values came from the shell. The exact values came either from the user (when they type commands) or another program. In either case, the shell will break command lines up into discrete words (stuff separated by spaces and tabs), and then create an argv array for the new program. The shell makes a couple of system calls to load and execute your program. Shell Variables One of the first new features that we will examine are shell variables. Like any programming language, the shell has variables. They are all strings, but strings can hold numbers too (like 12). The shell works with numeric values this way. There is a program call "expr" which will evaluate expressions using strings, but bash has built-in support for numeric operations on strings. Task Complete the following tasks. You may receive guidance from your instructor or other students. All code that you submit should be written by you. Write a shell script which reads text from the user into variables. Echo each word on a separate line. The shell will automatically tokenize convert to separate words) unquoted strings. Something like "for word in $string will split up $string into separate words. I would also like to see you running programs in subshells and capturing the output. This involves using the backquote (under - upper left of your keyboard). Strings in those quotes will be treated as command lines and run. The output of the command will be the value of the expression, so you can assign it to a variable. So, as a completely arbitrary task, for each file in the current directory, run "wc" to obtain the byte count for the file, and run "s" to get the size in kilobytes. Print both out for comparison. I don't care what the exact format is as long as the filename, byte count, and size in kilobytes is shown for each file. Hint: The shell's globbing feature" combined with a for loop would be a good choice for this assignment. Try out the following command: for a_file in echo "File Sa_file" done Again, for each file: Filename Size in Kilobytes Size in Bytes Turn in your program