Shell Scripting, Part I Flashcards
What does a SCRIPT contain?
contains a series of commands
What is an INTERPRETER?
executes commands in the script
What can you put in a script?
Anything you can type at the command line
What are Shell Scripts good for?
Automating tasks
What is #!
Sharp Bang (otherwise known as a “shebang”)
What follows a shebang #! ?
Whatever follows it is used as the interpreter
What if your script doesn’t contain a shebang?
Then commands are executed using your shell
What is chmod 755?
755 means read and execute access for everyone and also write access for the owner of the file. It’s the executable bitset.
What’s the difference?
#!/bin/csh #!/bin/ksh #!/bin/zsh
The scripts use different interpreters.
What are VARIABLES?
Storage locations that have a name.
- Name-value pairs
- Variables are CASE SENSITIVE
- By convention variables are uppercase, don’t use any spaces between equal sign
Are VARIABLES case sensitive?
YES!
What can variable names contain?
Letters, digits, and underscores, but can’t start with a digit. NO other special characters.
What is a TEST in a shell script?
A test allows you to test out a conditional expression to check for status.
What is the syntax for a TEST in a shell script?
[ condition-to-test-for ]
EXAMPLE:
[ -e /etc/passwd ]
WILL RETURN 1 or 0 (True or False)
How do you assign a command output to a variable in a shell script?
set it equal to $(command)
Example: SERVER_NAME=$(hostname)
How do you use a variable in a shell script?
use a $ (dollar sign) before the variable name, or enclose it with { } curly braces
EXAMPLE: echo “I like the $MY_SHELL shell”
EXAMPLE: echo “I like the ${MY_SHELL} shell.”
What is -d FILE
True if file is a directory
What is -e FILE
True if file exists
What is -f FILE
True if file exists and is a regular file
What is -r FILE
True if file is readable by you
What is -s FILE
True if file exists and is not empty
What is -w FILE
True if file is writable by you
What is -x FILE
True if file is executable by you
What is -z STRING
True if string is empty
What is -n STRING
True if string is not empty
What is STRING1 = STRING2
True if the strings are equal
What is STRING1! = STRING2
True if the strings are not equal
What is arg1 -eq arg2
True if arg1 is equal to arg2
What is arg1 -ne arg2
True if arg1 is not equal to arg2
What is arg1 -lt arg2
True if arg1 is less than arg2
What is arg1 -le arg2
True if arg1 is less than or equal to arg2
What is arg1 -gt arg2
True if arg1 is greater than arg2
What is arg1 -ge arg2
True if arg1 is greater than or equal to arg2