unix sys

Subdecks (3)

Cards (148)

  • Software layers include the Shell, which is the outer layer of an operating system, a program that allows a user to interact with the operating system, and a layer of programming that understands and executes the commands a user enters.
  • The most common shell on Linux systems is bash, which stands for Bourne Again Shell, an enhanced version of the original Unix shell program, sh, written by Steve Bourne.
  • Don't confuse the terminal emulator (putty) with the bash shell.
  • A shell script is a list of commonly used commands put into a text file and run together, designed to be run or executed by a Linux/Unix shell.
  • The extension .sh is often used to denote a shell script.
  • If you change the file permissions, you can make the shell script executable, allowing you to run the script.
  • Scripts can use variables inside the script.
  • The first line of a script must tell the script what shell to use.
  • Scripts can pass parameters to the script that can be used inside the script.
  • The data can then be accessed from within the script through the special variable 1, accessed using $1.
  • Scripts must be made readable and executable, as Unix does not rely on the extension.
  • In scripting, the string data is passed into the script.
  • Scripting involves passing data to a script via the command line: ./script3.sh data.
  • If a second piece of data is passed to the script, it can be accessed from within the script through the special variable 2, accessed using $2.
  • Scripts are text files.
  • The first line in all scripts must tell the OS what shell to use: We will use bash located in bin.
  • Lines beginning with # are comments.
  • The #! (pronounced hash-bang or pound-exclamation) when on the first line is treated as a special comment.
  • The remainder of the file contains the actual commands in the script.
  • Any commands you can type at the command line can go into a script.
  • Even though you have entered the commands into a script, you have to make it executable before it will run.
  • The script must also be readable.
  • Executable files in Unix do not have to have an extension (for example, .exe), but it will make your life easier if you adopt the convention to use the extension of .sh for bash shell scripts.
  • The $$$ variable in a Bash script gives the process ID of the current script.
  • The meaning of ‘num = 5’ is to store the value of 5 in the variable called num.
  • The SHELL variable is used to find out what shell you are using.
  • The $HOSTNAME variable in a Bash script gives the hostname of the machine the script is running on.
  • The $? variable in a Bash script gives the exit status of the most recently run process.
  • The $RANDOM variable in a Bash script returns a different random number each time it is referred to.
  • The name of a variable can contain only letters (a to z or A to Z), numbers ( 0 to 9) or the underscore character ( _).
  • The SHELL variable is a special variable called an environment variable, set by the system, and its value is represented by $SHELL.
  • A variable can be thought of as a jar with a name.
  • The $# variable in a Bash script indicates how many arguments were passed to the script.
  • A variable is a temporary store for a simple piece of information.
  • The $@ variable in a Bash script contains all the arguments supplied to the script.
  • A variable is a character string to which we assign a value.
  • In code, if we want to store the number 7 in a variable called num, it is done as follows: num = 7, where num is the variable and the value of 7 is stored in the variable.
  • The $LINENO variable in a Bash script returns the current line number in the script.
  • At a later point in the code, the value that is stored in the variable can be changed, for example: num = 5, where the value 7 is replaced with 5.
  • The $USER variable in a Bash script gives the username of the user running the script.