Sunday, October 24, 2010

Meaning of special characters in bash scripting?

Guys, You can refer the following information for the bash scripting :

===========
1. Basic : Special charecter :
# --> to comment
; --> command separator.
;; --> terminator, used after "case".

like :

case "$variable" in
abc) echo "\$variable = abc" ;;
xyz) echo "\$variable = xyz" ;;
esac
----------
. --> used to create hidden file and denotes current directory.
" -->partial quoting.
' --> full quoting.
\ -->escape [backslash]
/ -->Filename path separator [forward slash]
` -->command substitution. The `command` construct makes available the output of command for assignment to a variable.
: -->null command [colon]
! --> reverse
* -->wild card [asterisk] and arithmetic multiplication.
$ -->Variable substitution (contents of a variable) and end-of-line.
${} --> Parameter substitution.
$*, $@ --> positional parameters.
$$ -->process ID variable.
{} --> Block of code.

{} --> placeholder for text. ex : ls . | xargs -i -t cp ./{} $1
{} \; --> pathname.
[ ] -->test, array element,range of characters.
> &> >& >> < <> --> redirection.

Example :

scriptname >filename redirects the output of scriptname to file filename. Overwrite filename if it already exists.

command &>filename redirects both the stdout and the stderr of command to filename.

command >&2 redirects stdout of command to stderr.

scriptname >>filename appends the output of scriptname to file filename. If filename does not already exist, it is created.

\<, \> --> word boundary , ex : bash$ grep '\' textfile
| --> pipe , echo ls -l | sh

>| --> force redirection

|| and & , && --> logical operator, & = Run job in background
- --> option, ls -al
^ --> beginning-of-line
Ctl-A -->Moves cursor to beginning of line of text (on the command-line).
Ctl-b -- >Backspace
Ctl-E -->Moves cursor to end of line of text (on the command-line).
Ctl-C -->Break. Terminate a foreground job.
Ctl-D -->Log out from a shell
Ctl-F -->Moves cursor forward one character position (on the command-line).
Ctl-B -->Moves cursor backward one character position (on the command-line).
Ctl-H -->Erases characters the cursor backs over while backspacing.
Ctl-I -->Horizontal t
Ctl-L --> clear the terminal screen
Ctl-P -->old command that has been executed.
Ctl-O -->Issues a newline (on the command-line).
Ctl-y --> PASTE
===========

Try to test :)

No comments:

Post a Comment