Changes

Jump to: navigation, search

ULI101 Week 10

193 bytes added, 22:25, 31 August 2017
no edit summary
* <code>.bash_logout</code> :: Executed when you log out
=== <code>/etc/profile</code> ===
This file can only be modified by the root user. Affects the environment of all users, regardless of their default shell. Bash users can change their environment by modifying the <code>.bash_profile</code> or the <code>.bashrc</code> files. Different shells have different configuration files. Other configuration files such as <code>.profile</code> exist - read comments in your <code>.bash_rc</code> file to find out more
=== <code>.bashrc</code> and <code>.bash_profile</code> ===
Located in the user’s home directory. These files are executed every time a user logs in or creates a new shell. Things vary depending whether the shell is interactive or not. By modifying either one of these files, each user can change his individual working environment. They can be used for the following:
* Mapping new keys on the keyboard
== Shell History ==
Many shells keep a history of recently executed command lines in a file. This history is used by users to save time, when executing same or similar commands over and over. Bash uses the up/down arrow keys. Use the Ctrl+r to search by keyword. Bash stores it’s history in the <code>.bash_history</code> file
== Alias ==
A way to create “shortcuts” or temporary commands in UNIX. Stored in memory, while the user is logged in. Usually found in the <code>.bash_profile</code>. Syntax:
<code>alias clearfile=”cat /dev/null &gt;”</code>
== Shell Variables ==
Shell variables a classified in 2 groups:
Variables can be read/write or read-only. Name of a variable can be any sequence of letters and numbers, but it must not start with a number.
=== Common Shell Variables ===
Shell environment variables shape the working environment whenever you are logged in. Common shell variables include:
{|
| <code>PS1</code>
| primary prompt
|-
| <code>PWD</code>
| present working directory
|-
| <code>HOME</code>
| absolute path to user’s home
|-
| <code>PATH</code>
| list of directories where executables are
|-
| <code>HOST</code>
| name of the host
|-
| <code>USER</code>
| name of the user logged in
|-
| <code>SHELL</code>
| current shell
|}
The <code>set</code> command will display all available variables
=== The <code>PATH </code> variable ===
* <code>PATH</code> is an environment variable present in Unix/Linux operating systems, listing directories where executable programs are located
* Use <code>./</code> prefix or modify the <code>PATH</code> as needed
=== Assigning a Value ===
Syntax: <code>name=value</code>
* If no variable name is supplied a list of defined read only variables will be displayed
=== Removing Variables ===
<code>variable=</code>
Read-only variables cannot be removed, you must log out for them to be cleared.
=== Variable Substitution ===
Whenever you wish to read a variable (its contents), use the variable name preceded by a dollar sign ($). This is commonly called ''variable substitution''.
Alice
</source>
 
 
= Introduction to Shell Scripting =
fi
</source>
 
= <code>test</code> Command =
{|
| <code>-e</code>
| file exists
|-
| <code>-d</code>
| file exists and is a directory
|-
| <code>-s</code>
| file exists and has a size greater than zero
|-
| <code>-w</code>
| file exists and write permission is granted
|}
221
edits

Navigation menu