Week 8 - Shell Scripts Part 2 Flashcards
Loops
Perform a set of commands repeatedly
Looping statements:
while statement
- interpreter continues executing
the code in the while loop portion of the script as long as the condition is true
The while loop
– Repeats commands between
do and done statements
– As long as the tested condition is
true
* When the command after the
while statement returns an exit status code greater than 0
– while statement fails
– Program executes commands after
done statement
Basic Arithmetic Expression
Arithmetic expression should be place inside
double parenthesis: (( expression ))
The for Loop
- Repeats the commands between
do and done a specified number of times
– Each time the script carries out the commands in the loop, a new value is given to a variable
– Assign this value in the command with positional parameters
Shell scripts loops used
While and For loops are used
Loops are used to repeat actions on different variables
Viewing file permissions command
> ls -l
Permissions User
The file owner
Permissions Group
A group of users; users are divided into groups to facilitate administrative tasks.
- Each user assigned to a primary group e.g. “users”
– Users can be members of other groups ( secondary groups )
– Each file is owned by a user and a group
– If you create a file, it is owned by
you and your primary group
– Anyone who is a member of that group (primary or secondary), has file permissions specified by that files group permission.
Permissions Other
Everyone else on Linux System
Linux file permissions
Mechanism to provide protection to OS
– Users don’t misuse file system resources
– Permission protects the entities of the file system so users cannot misuse entities owned by another user
* Permissions specify who can access a file and the type of access.
– File and Directory owned by a user
Read, Write and Excecute
Functions of these permissions differ, depending on whether they’re applied to files or directories
r (Read)
Gives users permission to open a file and view its contents
Allows users to list a directory’s contents with commands such as ls
w (Write)
Gives users permission to open and file and edit its contents
w (Write)
Gives users permission to open and file and edit its contents
Allows users to add or remove files and subdirectories
x (Execute)
Allows users to run the file (as long as it is a program or a script)
Allows users to switch to directory with cd command to read a directory’s contents and add/remove files and subdirectories, you must have execute permission