GithubHelp home page GithubHelp logo

bash's Introduction

Bash scripts concepts

Special Parameters

The Special parameters are: *@#0$?_!-

  1. $* expand to the value of all positional parameters combined
  2. $@ same as the above
  3. $# expands to the number of positional parameters.
  4. $0 contains the path to the currently running script or to the shell itself if no script is being executed.
  5. $$ contains the process identification number (PID) of the current process.
  6. $_ is set to the last argument to that command.
  7. $? is set to the exit code of the last-executed command.
  8. $! contains the PID of the last command executed in the background
  9. $- is set to the option flags currently in effect

Variables

A variable is a parameter denoted by a name; a name is a word containing only letters, numbers, or underscores and beginning with a letter or an underscore.

name=VALUE

NOTE: Bash is very particular about spacing: note that there are no spaces before the = and none after. If you have spaces, the command would not work.

Formatting and Printing data

printf is derived from the C programming language function of the same name;

printf FORMAT ARG ...

Escape Sequences

Escape sequences are single letters preceded by a backslash:

  • \a::Alert
  • \b::Backspace
  • \e::Escape character
  • \f::Form feed
  • \n::Newline
  • \r::Carriage return
  • \t::Horizontal tab
  • \v::Vertical tab
  • \\::backslash
  • \nnn::A character specified by one to three octal digits
  • \xHH::A character specified by one or two hexadecimal digits

The backslashes must be protected from the shell by quotes or another backslash:

printf "Q\t\141\n\x42\n"

Format specifiers

The format specifiers are letters preceded by a percent sign. Optional modifiers may be placed between the two characters. The specifiers are replaced by thecorresponding argument. When there are more arguments than specifiers, the format string is reused until all the arguments have been consumed. The most commonly used specifiers are %s, %d, %f, and %x.

The %s specifier prints the literal characters in the argument:

$ printf "%s\n" Print arguments on "separate lines"

%b is like %s except that escape sequences in the arguments are translated:

$ printf "%b\n" "Hello\nworld" "12\tword"

Integers are printed with %d. The integer may be specified as a decimal, octal (using a leading 0), or hexadecimal (preceding the hex number with 0x) number. If the number is not a valid integer, printf prints an error message:

$ printf "%d\n" 23 45 56.78 0xff 011

bash's People

Contributors

thiago18l avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.