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)