Check and change your shell
$ echo $SHELL $ echo $0
Change your default shell (e.g. to zsh):
$ chsh -s /usr/bin/zsh
The POSIX (the Portable Operating System Interface) shell is the standard Unix shell, i.e. it was formally defined and shipped in a published standard, it has many competing implementations on many different operating systems, but are compatible.
POSIX shell is basically Bourne shell, lives at the standardized location
The POSIX standard does not recognize long flags like
grep --file=FILE, but only the short flags like
grep -f. (Because it does not define
getopt_long function, only
Bash: Bourne Again Shell
In many Linux distros, bash is the default shell, and
/bin/sh is symlinked to
Bash is not standardized, but there's only one implementation of bash (i.e. bash is defined by its implementation).
#! is called a shebang. Scripts will execute using the interpreter specified on a first line.
Make Shell Script Portable
If you use the POSIX shell
/bin/sh, just add
#!/bin/sh to the top of your script. The location is standardized.
If you use other shells, e.g. bash, use
#!/usr/bin/env bash instead of
#!/bin/bash as shebang. Because bash is not always in the same location. If you have multiple versions of a shell installed, use
env will make sure the first executable in the
PATH will be used.
Set Environment Variable
$ x="hello" y="world" bash -c 'echo $x $y' hello world
bash -c: "commands are read from the first non-option argument command_string. If there are arguments after the command_string, the first argument is assigned to 0 sets the name of the shell, which is used in warning and error messages."
Allows you to create a VPN connection from your machine to any remote server that you can connect to via ssh.
You must have root access on the local machine, but you can have a normal account on the server.
grep | wc -> grep -c sort | uniq | wc -> sort -u | wc
List all variables
$ env TERM=xterm-256color SHELL=/bin/sh JAVA_HOME=... HADOOP_HOME=...
env is equivalent to
Show A Specific Variable
$ env | grep TERM xterm-256color
$ echo $TERM xterm-256color
Remove A Variable
$ unset <VAR_NAME>
List of Built-in Variables
HOME- Home directory of the user.
IFS- Internal Field Separator. Contains a string of characters which are used as word separators in the command line. The string normally consists of the space, tab and the newline characters. To see them you will have to do an octal dump:
$ echo $IFS | od -bc
PS1 and PS2- Primary and secondary prompts in bash. PS1 is set to
$by default and PS2 is set to
>. To see the secondary prompt:
$ ls |
USER- User login name.
TERM- indicates the terminal type being used. This should be set correctly for editors like Vim to work correctly.
SHELL- Determines the type of shell that the user sees on logging in.
LOGNAME- login name
Ctrl-R: search backward.
Ctrl-S: search forward.
For example, to search
grep commands in your history and cycle through alternatives: