Differences between revisions 36 and 39 (spanning 3 versions)
Revision 36 as of 2009-01-02 11:26:55
Size: 6217
Editor: pgas
Comment: spam
Revision 39 as of 2009-01-04 13:12:16
Size: 4846
Editor: 94-76-213-77
Comment: comment2 http://saga1212.001webs.com/bar-jobs-in-london.html job centres london http://saga1212.001webs.com/book-reading-barnes-and.html bomani armah read a book lyrics http://saga1212.001webs.c
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
<<Anchor(Commands_And_Arguments)>>
== Commands And Arguments ==

[[BASH]] reads commands from its input (which is either a terminal or a file). These commands can be aliases, functions, builtins, keywords, or executables.

 * '''Aliases''': Aliases are a way of shortening commands. They are only used in '''interactive''' shells, not in '''scripts'''. An alias is a ''name'' that is mapped to a certain ''string''. Whenever that ''name'' is used as a command name, it is replaced by the ''string'' before executing the command.
    So, instead of executing:
    {{{
     $ nmap -P0 -A --osscan_limit 192.168.0.1}}}
    You could use an alias like this:
    {{{
     $ alias nmapp='nmap -P0 -A --osscan_limit'
     $ nmapp 192.168.0.1}}}

 * '''Functions''': Functions in [[BASH]] are somewhat like aliases, but more powerful. Unlike aliases they can be used in '''scripts'''. A function contains shell commands, very much like a small script. When a function is called, the commands in it are executed.

 * '''Builtins''': [[BASH]] has some basic commands built into it, such as `cd` (change directory), `if` (conditional command execution), and so on. You can think of them as functions that are provided already.

 * '''Keywords''': Keywords are quite like builtins, but the main difference is that special parsing rules apply to them. For example, `[` is a bash builtin, while `[[` is bash keyword. They are both used for testing stuff, but since `[[` is a keyword rather than a builtin, it benefits from a few special parsing rules which make it a lot better:
    {{{
     $ [ a < b ]
    -bash: b: No such file or directory
     $ [[ a < b ]]}}}
    The first example returns an error because bash tries to redirect the file `b` to the command `[ a ]` (See [[#File_Redirection|File Redirection]]). The second example actually does what you expect it to. The special character `<` no longer has it's special meaning of `File Redirection` operator.

 * '''Executables''': The last option of commands that can be executed in bash is executables. The command name of an executable is always the pathname of to the executable to execute. If the executable is in the current directory; use `./myprogram`. If it's in the `/usr/local/bin` directory, use `/usr/local/bin/myprogram`.
    To make life a little easier for you, though, [[BASH]] uses a variable that tells it where to find applications in case you just use the name of the application but not its full pathname. This variable is called `PATH`, and it is a set of directory names separated by colons -- for example, `/bin:/usr/bin`. When a command is specified in [[BASH]] without a pathname (e.g. `myprgram`, or `ls`), and it isn't an alias, function, builtin or keyword, [[BASH]] searches through the directories in `PATH`, in order from left to right, to see whether they contain an executable by the name of the command name you typed.

Each command can be followed by arguments. Arguments are words you specify after the command name. Arguments are separated from the command name and from each other by white space. This is important to remember. For example, the following is '''wrong''':
{{{
    $ [-f file]
}}}

You want the `[` command name to be separated from the arguments `-f`, `file` and `]`. If you do not separate `[` and `-f` from each other with whitespace, bash will think you are trying to execute the command name `[-f` and look in `PATH` for a program named `[-f`. Additionally, the arguments `file` and `]` also need to be separated by spaces. The `[` command expects the last argument to be `]`. The correct command separates all arguments with spaces:
{{{
    $ [ -f file ]
}}}

'''NOTE:'''<<BR>>
'''It is very important that you understand how this works exactly.''' If you don't grasp these concepts well, the quality of your code will degrade significantly and you will introduce very dangerous bugs. Read [[#Argument_Splitting|Argument Splitting]] very carefully.

{{{
    $ ls
    a b c
}}}
`ls` is a command that lists files in the current directory. It's intended to be used '''only for producing human-readable results'''. Please don't try to parse, pipe, grep, capture, read, or loop over the output of `ls` in a script. It's dangerous and there's always a better way. While an invaluable tool on the interactive shell, `ls` should therefore never be used in scripts. You will understand why as you go through this guide.

{{{
    $ mkdir d
    $ cd d
    $ ls
}}}
`mkdir` is a command that creates a new directory. We specified the argument `d` to that command. This way, the application `mkdir` is instructed to create a directory called `d`. After that, we use the builtin command `cd` to change the shell's current directory to `d`. `ls` shows us that the current directory (which is now `d`) is empty, since it doesn't display any filenames.

In [[BASH]] scripts, arguments that were passed to the script are saved in 'Positional Parameters'. You can read these by using `$1`, `$2`, and so on for the respective argument. You can also use `$@` and `$*` but more about this later on.

--------
 . '''Tip: <<BR>> You can use the `type` command to figure out the type of a command. <<BR>> For example:'''
{{{
    $ type rm
    rm is hashed (/bin/rm)
    $ type cd
    cd is a shell builtin
}}}
----
 . '''In The Manual: [[http://www.gnu.org/software/bash/manual/bashref.html#SEC16|Simple Commands]]'''
----
 . ''Alias'': A name that is mapped to a string. Whenever that name is used as a command, it is replaced by the string it has mapped. <<BR>> ''Function'': A name that is mapped to a script. Whenever that name is used as a command, the script is called with the arguments provided to the function's name on the command line. <<BR>> ''Builtin'': Certain features have been built into [[BASH]]. These are handled internally whenever they are executed on the command line (and often do not create a new process). <<BR>> ''Application'': A binary that can be executed by referring to it (`/bin/ls`) or if its location is in your `PATH` variable, you can execute it simply by using its name (`ls`).
--------
comment2
http://saga1212.001webs.com/bar-jobs-in-london.html job centres london
http://saga1212.001webs.com/book-reading-barnes-and.html bomani armah read a book lyrics
http://saga1212.001webs.com/amathus-beach-hotel-limassol.html amatuercumshots thumblogger com
http://saga1212.001webs.com/heavyhands-fitness-equipment.html vjs world of home fitness equipment
http://saga1212.001webs.com/buy-and-sell-tickets.html sell tickets online
http://saga1212.001webs.com/daily-news-newspaper-new-york.html daily express news paper
http://saga1212.001webs.com/hair-extension-removal.html hair extension removal
http://saga1212.001webs.com/tickets-to-drayton-manor-theme-park.html theme park tickets no
http://saga1212.001webs.com/albrook-airport-panama-city.html albrook airport panama city
http://saga1212.001webs.com/applewood-restaurant-mankato.html applewood restaurant vancouver
http://saga1212.001webs.com/chocolate-dream-pie-recipe.html chocolate fairy cake recipes
http://saga1212.001webs.com/anti-counterfeiting-program.html anti cybersquatting protection act
http://saga1212.001webs.com/rental-homes-in-sherman.html rental homes in sunriver oregon
http://saga1212.001webs.com/accounting-job-descriptions.html accounting jobs in frederick md
http://saga1212.001webs.com/any-who-telephone-directory.html anyang forging press machinery industry co ltd
http://saga1212.001webs.com/distilled-water-filters.html dual undersink water filter system
http://saga1212.001webs.com/factory-chicken-piccata-recipe.html fettuccine alfredo with chicken recipe
http://saga1212.001webs.com/anderson-rocketech-reloaded.html anderson silva weight class
http://saga1212.001webs.com/day-forecast-new-york-weather.html day forecast weather malaga
http://saga1212.001webs.com/shrimp-noodle-recipe.html shrimp recipe ideas
http://saga1212.001webs.com/north-carolina-job-listings.html superintendent jobs in north carolina
http://saga1212.001webs.com/free-modern-audio-books.html cheap audio books on
http://saga1212.001webs.com/hair-cut-trends-2008.html hair cuts and face shapes
http://saga1212.001webs.com/curious-george-birthday-party-ideas.html engagement party gift idea
http://saga1212.001webs.com/acupuncture-plantar-faciitis.html acura dealers in los angeles
http://saga1212.001webs.com/discount-lift-tickets-park-city-utah.html wild river country discount tickets
http://saga1212.001webs.com/ny-home-builders-association.html of home builders in houston
http://saga1212.001webs.com/advertising-agencies-malaysia.html advertising agency creative
http://saga1212.001webs.com/albuquerque-hotels-close-to.html albuquerque international sunport
http://saga1212.001webs.com/alter-table-add-column-command.html alter table add column not null
http://saga1212.001webs.com/body-hair-removal-for-men-in.html brazilian hair removal
http://saga1212.001webs.com/apple-cider-vinegar-lose-weight.html apple cider vineger tablets
http://saga1212.001webs.com/acura-legend-online-service-manual.html acura mdx transmission fluid change
http://saga1212.001webs.com/advertising-to-college-students.html advertising vs television advertising
http://saga1212.001webs.com/alternative-investment-markets.html alternative investment solution
http://saga1212.001webs.com/road-maps-of-the-united-states.html map of united states with major cities
http://saga1212.001webs.com/modern-bob-haircuts.html modern celebrity haircuts
http://saga1212.001webs.com/discount-tickets-to-schlitterbaun.html discount tickets to dixie stampede in
http://saga1212.001webs.com/annualize-daily-standard-deviation.html annualize monthly standard deviation
http://saga1212.001webs.com/united-states-postal-service-web.html united states postal service phone number
http://saga1212.001webs.com/artificial-insemination-school.html artificial insemination support
http://saga1212.001webs.com/pizza-casserole-recipe.html quick pizza recipes
http://saga1212.001webs.com/ground-beef-casserole-recipe.html recipe corn beef and cabbage
http://saga1212.001webs.com/wall-decor-and-home-accents.html your home decor
http://saga1212.001webs.com/are-siberian-tigers-extinct.html are skeletal muscles multinucleated
http://saga1212.001webs.com/birthday-gift-wrapping-ideas.html female 40th birthday gift ideas
http://saga1212.001webs.com/womens-medium-hair-cuts.html womens short haircut
http://saga1212.001webs.com/roast-pepper-recipe.html slow cooker pepper steak recipe
http://saga1212.001webs.com/affordable-web-site-hosting-package.html affordable website design company
http://saga1212.001webs.com/tracker-used-boats.html used bayliner boats
http://saga1212.001webs.com/read-book-of-mormon.html i read banned books
http://saga1212.001webs.com/access-to-high-speed-internet.html access to information commission

comment2 http://saga1212.001webs.com/bar-jobs-in-london.html job centres london http://saga1212.001webs.com/book-reading-barnes-and.html bomani armah read a book lyrics http://saga1212.001webs.com/amathus-beach-hotel-limassol.html amatuercumshots thumblogger com http://saga1212.001webs.com/heavyhands-fitness-equipment.html vjs world of home fitness equipment http://saga1212.001webs.com/buy-and-sell-tickets.html sell tickets online http://saga1212.001webs.com/daily-news-newspaper-new-york.html daily express news paper http://saga1212.001webs.com/hair-extension-removal.html hair extension removal http://saga1212.001webs.com/tickets-to-drayton-manor-theme-park.html theme park tickets no http://saga1212.001webs.com/albrook-airport-panama-city.html albrook airport panama city http://saga1212.001webs.com/applewood-restaurant-mankato.html applewood restaurant vancouver http://saga1212.001webs.com/chocolate-dream-pie-recipe.html chocolate fairy cake recipes http://saga1212.001webs.com/anti-counterfeiting-program.html anti cybersquatting protection act http://saga1212.001webs.com/rental-homes-in-sherman.html rental homes in sunriver oregon http://saga1212.001webs.com/accounting-job-descriptions.html accounting jobs in frederick md http://saga1212.001webs.com/any-who-telephone-directory.html anyang forging press machinery industry co ltd http://saga1212.001webs.com/distilled-water-filters.html dual undersink water filter system http://saga1212.001webs.com/factory-chicken-piccata-recipe.html fettuccine alfredo with chicken recipe http://saga1212.001webs.com/anderson-rocketech-reloaded.html anderson silva weight class http://saga1212.001webs.com/day-forecast-new-york-weather.html day forecast weather malaga http://saga1212.001webs.com/shrimp-noodle-recipe.html shrimp recipe ideas http://saga1212.001webs.com/north-carolina-job-listings.html superintendent jobs in north carolina http://saga1212.001webs.com/free-modern-audio-books.html cheap audio books on http://saga1212.001webs.com/hair-cut-trends-2008.html hair cuts and face shapes http://saga1212.001webs.com/curious-george-birthday-party-ideas.html engagement party gift idea http://saga1212.001webs.com/acupuncture-plantar-faciitis.html acura dealers in los angeles http://saga1212.001webs.com/discount-lift-tickets-park-city-utah.html wild river country discount tickets http://saga1212.001webs.com/ny-home-builders-association.html of home builders in houston http://saga1212.001webs.com/advertising-agencies-malaysia.html advertising agency creative http://saga1212.001webs.com/albuquerque-hotels-close-to.html albuquerque international sunport http://saga1212.001webs.com/alter-table-add-column-command.html alter table add column not null http://saga1212.001webs.com/body-hair-removal-for-men-in.html brazilian hair removal http://saga1212.001webs.com/apple-cider-vinegar-lose-weight.html apple cider vineger tablets http://saga1212.001webs.com/acura-legend-online-service-manual.html acura mdx transmission fluid change http://saga1212.001webs.com/advertising-to-college-students.html advertising vs television advertising http://saga1212.001webs.com/alternative-investment-markets.html alternative investment solution http://saga1212.001webs.com/road-maps-of-the-united-states.html map of united states with major cities http://saga1212.001webs.com/modern-bob-haircuts.html modern celebrity haircuts http://saga1212.001webs.com/discount-tickets-to-schlitterbaun.html discount tickets to dixie stampede in http://saga1212.001webs.com/annualize-daily-standard-deviation.html annualize monthly standard deviation http://saga1212.001webs.com/united-states-postal-service-web.html united states postal service phone number http://saga1212.001webs.com/artificial-insemination-school.html artificial insemination support http://saga1212.001webs.com/pizza-casserole-recipe.html quick pizza recipes http://saga1212.001webs.com/ground-beef-casserole-recipe.html recipe corn beef and cabbage http://saga1212.001webs.com/wall-decor-and-home-accents.html your home decor http://saga1212.001webs.com/are-siberian-tigers-extinct.html are skeletal muscles multinucleated http://saga1212.001webs.com/birthday-gift-wrapping-ideas.html female 40th birthday gift ideas http://saga1212.001webs.com/womens-medium-hair-cuts.html womens short haircut http://saga1212.001webs.com/roast-pepper-recipe.html slow cooker pepper steak recipe http://saga1212.001webs.com/affordable-web-site-hosting-package.html affordable website design company http://saga1212.001webs.com/tracker-used-boats.html used bayliner boats http://saga1212.001webs.com/read-book-of-mormon.html i read banned books http://saga1212.001webs.com/access-to-high-speed-internet.html access to information commission

BashGuide/CommandsAndArguments (last edited 2023-06-20 18:36:11 by larryv)