Login shells read one or more startup files as shown below:
File | Content |
---|---|
/etc/profile | A global configuration script that applies to all usres |
~/.bash_profile | A user’s personal startup file. Can be used to extend or override settings in the global configuration script. |
~/.bash_login | If ~/.bash_profile is not found, bash attempts to read this script. |
~/.profile | If neither ~/.bash_profile nor ~/.bash_login is found, bash attempts to read this file. This is the default in Debian-based distributions, such as Ubuntu. |
Non-login shell sessions read the following startup files:
File | Content |
---|---|
/etc/bash.bashrc | A global configuration script that applies to all users. |
~/.bashrc | A user’s personal startup file. Can be used to extend or override settings in the global configuration script. |
In addition to reading the startup files above, non-login shells also inherit the environment from their parent process, usually a login shell.
#!/bin/bash
title="This is a title"
cat <<- EOF
<html>
<head>
<title>
$title
</title>
</head>
<body>
$title
</body>
</html>
EOF
To create a variable, put a line in your script that contains the name of the variable followed immediately by an equal sign (“=”). No spaces are allowed. After the equal sign, assign the information you wish to store.
Expression | Description |
---|---|
-d file | True if file is a directory |
-e file | True if file exists |
-f file | True if file exists and is a regular file |
-L file | True if file is a symbolic link |
-r file | True if file readable by you. |
-w file | True if file writable by you. |
-x file | True if file executable by you. |
file1 -nt file2 | True if file1 is newer than(according to the modification) |
file1 -ot file2 | True if ……..older …. |
-z string | True if string is empty |
-n string | True if string is not empty |
str1 = str2 | True if str1 equals str2 |
str1 != str2 | ………..not equal … |