shell scripting notes ch3 variables alias BASH_COMMAND BASH_SOURCE

From security perspective, it's very bad practice to put a dot (.) in your PATH, especially at the front of the PATH.

You can set an alias in your ~/.bashrc file
alias less="less -X"

the command unalias less  removes this aliasing

to bypass an alias - is to put a backslash before the command
\rm - will call the analiased rm command

HISTIGNORE is a colon-separated list of commands that shouldn't be stored in the history

if you need to go via a proxy server, the ~/.wgetrc file can be used to set proxy settings for the wget tool.

In the shell there is no concept of a "type", you could say that everything is a string.

There is no need to explicitly declare the variable before using it.

command substitution: VAR=`date`, VAR=$(date)
no spaces are permitted around the equal sign

Bourne shell doesn't allow VAR=$(date) syntax

echo -n - tells echo not to put a newline character at the end

 You cannot change the values of variables $0 -filename, $1 - first parameter, etc

Variables cannot start with a digit

$# variable tells a script how many parameters it was called with
if [ "$#" -eq "2" ]

basename $0

The multiple spaces between "two" and "three" are preserved properly only when the script processes "$@" within double quotes

$? - variable return code of the last-run command.
In practice for grep, a return code of 1 means "no match" and 2 or above means that some kind of error occurred within grep itself. Exit code zero indicates success

$! - you can run the process in the background and find its PID

There is no concept in the shell of declaring variables, because they have no type.

BASHOPTS is new in bash 4.1. It is a list of the enables shell options.

SHELLOPTS is similar to BASHOPTS

set -x - display every command before it executes it.

BASH_COMMAND is the name of the currently exeuted command.

BASH_SOURCE, FUNCNAME, LINENO and BASE_LINENO are useful debugging variables that tell you where you are in the script, even when you have multiple files in use

PIPESTATUS is an array of the exit status of the last run pipeline or command

PPID is set to the Process ID of the process that called this shell or shell script.
$$ is another special variable which provides  the Process ID of this shell itself.

REPLY is the default variable name for read if none are supplied

BASH_XTRACEFD is new to Bash 4.1. When used with the -x feature this variable allows the script itself to define what file the output goes to ( by default , it goes to stderr)

PATH is used to find programs, it searches from left to right.
If you create /home/steve/bin/ls which you want to use instead, you can force the shell to forget its hashes by running hash -r

TMOUT - read builtin will exit with a value greater than 128 if it times out.



Comments

Popular posts from this blog

HAproxy logging

teamcity Automatic Agent Start under Linux

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all