Differences between revisions 8 and 34 (spanning 26 versions)
Revision 8 as of 2008-10-31 18:36:24
Size: 6211
Editor: pgas
Comment:
Revision 34 as of 2009-01-02 05:46:28
Size: 4873
Editor: 94-76-213-77
Comment: comment5 http://xfveisw.hostevo.com/arburg-practical-guide-to-injection.html arbus client personalarchivalengine http://xfveisw.hostevo.com/archer-house-in-northfield-mn.html arches apartments wes
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`).
--------
comment5
http://xfveisw.hostevo.com/arburg-practical-guide-to-injection.html arbus client personalarchivalengine
http://xfveisw.hostevo.com/archer-house-in-northfield-mn.html arches apartments west lafayette
http://xfveisw.hostevo.com/baked-chicken-wings-recipes.html best baked beans recipe
http://xfveisw.hostevo.com/anti-virus-mobile-activation-key.html anti virus para windows vista
http://xfveisw.hostevo.com/vip-tickets-to-v-festival.html ultra music festival miami tickets
http://xfveisw.hostevo.com/cornroll-hair-style.html create a new hairstyle
http://xfveisw.hostevo.com/rachel-bilson-hairstyles.html red curly hair styles
http://xfveisw.hostevo.com/theatre-org-uk-buytickets.html momix lunar sea tickets peacock theatre
http://xfveisw.hostevo.com/air-force-mess-dress-uniform.html air force museum foundation
http://xfveisw.hostevo.com/the-home-builders.html top home builders in houston
http://xfveisw.hostevo.com/kids-homemade-halloween-costume.html kids pumpkin halloween costumes
http://xfveisw.hostevo.com/aquagen-hard-to-say-i-m-sorry.html aquagen rozalla everybodys
http://xfveisw.hostevo.com/anxiety-depression-scale-hads.html anxiety disorder children symptoms
http://xfveisw.hostevo.com/free-rhubarb-pie-recipe.html free rice krispie treats recipe
http://xfveisw.hostevo.com/architectural-woodwork-institute.html architecturally designed house plans
http://xfveisw.hostevo.com/find-new-hairstyle.html finding the hairstyle
http://xfveisw.hostevo.com/annuaire-telephonique-tunisie.html annual compound interest calculator
http://xfveisw.hostevo.com/aerobed-instasleep-raised-full.html aerobed queen inflatable mattresses amp
http://xfveisw.hostevo.com/online-news-paper-of-pakistan.html employment news paper online
http://xfveisw.hostevo.com/2-www-allalliedhealthschools-com-florida-career-college-get.html health careers school
http://xfveisw.hostevo.com/agility-training-portland-or.html agira canadian war cemetery
http://xfveisw.hostevo.com/bruce-springsteen-tickets.html bruce springsteen tickets boston
http://xfveisw.hostevo.com/abington-hall-conference-centre.html abington school district vs schemp
http://xfveisw.hostevo.com/7-www-careerchoicewizard-com-nursing-university-get-associate-degree.html florida atlantic university careers
http://xfveisw.hostevo.com/applied-statistical-signal-analysis.html applied statistical signal analysis
http://xfveisw.hostevo.com/of-haircut-ideas-for.html of seaguls haircut
http://xfveisw.hostevo.com/texas-christian-university-book-store.html christian books for single women
http://xfveisw.hostevo.com/apo-diclo-diclofenac-sodium.html apocalypse now mind over matter
http://xfveisw.hostevo.com/akros-alternative-investments.html aksh pharmaceuticals pvt ltd
http://xfveisw.hostevo.com/used-cars-guelph-ontario.html used cars dealers west
http://xfveisw.hostevo.com/adventist-sabbath-school-lessons.html adventist universities in usa
http://xfveisw.hostevo.com/my-career-education-com-arizona-schools-and.html stanford medical school career
http://xfveisw.hostevo.com/long-hair-styles-over-40.html long hair styles round face
http://xfveisw.hostevo.com/peach-pie-recipe.html pie crust recipes
http://xfveisw.hostevo.com/a-video-vixen-book-online.html view comic books online
http://xfveisw.hostevo.com/cd-key-windows-vista.html windows vista screenshots
http://xfveisw.hostevo.com/roosters-home-decor.html rustic country home decor
http://xfveisw.hostevo.com/alchemist-reflections-special.html alchoholics annonymous meetings
http://xfveisw.hostevo.com/used-car-dealer-ships.html used modified cars
http://xfveisw.hostevo.com/akademisches-gymnasium-graz.html akai reel to reel tape deck
http://xfveisw.hostevo.com/thrillers-audio-books.html audio books books on
http://xfveisw.hostevo.com/ampgroup-com-shareholdercentre.html amphetamine dextroamphetamine extended
http://xfveisw.hostevo.com/100-free-christian-online-dating.html free online dating for girls
http://xfveisw.hostevo.com/allen-county-indiana-small-claims.html allen county indiana warrants
http://xfveisw.hostevo.com/dixie-stampede-creamy-vegetable-soup-recipe.html e fagoli soup recipe
http://xfveisw.hostevo.com/ahima-american-health-information.html ahista ahista milte hain dil
http://xfveisw.hostevo.com/get-cheapest-airline-tickets.html airline ticketing software
http://xfveisw.hostevo.com/accounting-salary-in-canada.html accounting software applications
http://xfveisw.hostevo.com/affiliate-internet-marketing-online.html affiliate management software
http://xfveisw.hostevo.com/akademia-ekonomiczna-wroclaw.html akademia gorniczo hutnicza im st
http://xfveisw.hostevo.com/free-christian-books-request-form.html family christian book store colorado
http://xfveisw.hostevo.com/beef-rissole-recipes.html beef rissoles recipes

comment5 http://xfveisw.hostevo.com/arburg-practical-guide-to-injection.html arbus client personalarchivalengine http://xfveisw.hostevo.com/archer-house-in-northfield-mn.html arches apartments west lafayette http://xfveisw.hostevo.com/baked-chicken-wings-recipes.html best baked beans recipe http://xfveisw.hostevo.com/anti-virus-mobile-activation-key.html anti virus para windows vista http://xfveisw.hostevo.com/vip-tickets-to-v-festival.html ultra music festival miami tickets http://xfveisw.hostevo.com/cornroll-hair-style.html create a new hairstyle http://xfveisw.hostevo.com/rachel-bilson-hairstyles.html red curly hair styles http://xfveisw.hostevo.com/theatre-org-uk-buytickets.html momix lunar sea tickets peacock theatre http://xfveisw.hostevo.com/air-force-mess-dress-uniform.html air force museum foundation http://xfveisw.hostevo.com/the-home-builders.html top home builders in houston http://xfveisw.hostevo.com/kids-homemade-halloween-costume.html kids pumpkin halloween costumes http://xfveisw.hostevo.com/aquagen-hard-to-say-i-m-sorry.html aquagen rozalla everybodys http://xfveisw.hostevo.com/anxiety-depression-scale-hads.html anxiety disorder children symptoms http://xfveisw.hostevo.com/free-rhubarb-pie-recipe.html free rice krispie treats recipe http://xfveisw.hostevo.com/architectural-woodwork-institute.html architecturally designed house plans http://xfveisw.hostevo.com/find-new-hairstyle.html finding the hairstyle http://xfveisw.hostevo.com/annuaire-telephonique-tunisie.html annual compound interest calculator http://xfveisw.hostevo.com/aerobed-instasleep-raised-full.html aerobed queen inflatable mattresses amp http://xfveisw.hostevo.com/online-news-paper-of-pakistan.html employment news paper online http://xfveisw.hostevo.com/2-www-allalliedhealthschools-com-florida-career-college-get.html health careers school http://xfveisw.hostevo.com/agility-training-portland-or.html agira canadian war cemetery http://xfveisw.hostevo.com/bruce-springsteen-tickets.html bruce springsteen tickets boston http://xfveisw.hostevo.com/abington-hall-conference-centre.html abington school district vs schemp http://xfveisw.hostevo.com/7-www-careerchoicewizard-com-nursing-university-get-associate-degree.html florida atlantic university careers http://xfveisw.hostevo.com/applied-statistical-signal-analysis.html applied statistical signal analysis http://xfveisw.hostevo.com/of-haircut-ideas-for.html of seaguls haircut http://xfveisw.hostevo.com/texas-christian-university-book-store.html christian books for single women http://xfveisw.hostevo.com/apo-diclo-diclofenac-sodium.html apocalypse now mind over matter http://xfveisw.hostevo.com/akros-alternative-investments.html aksh pharmaceuticals pvt ltd http://xfveisw.hostevo.com/used-cars-guelph-ontario.html used cars dealers west http://xfveisw.hostevo.com/adventist-sabbath-school-lessons.html adventist universities in usa http://xfveisw.hostevo.com/my-career-education-com-arizona-schools-and.html stanford medical school career http://xfveisw.hostevo.com/long-hair-styles-over-40.html long hair styles round face http://xfveisw.hostevo.com/peach-pie-recipe.html pie crust recipes http://xfveisw.hostevo.com/a-video-vixen-book-online.html view comic books online http://xfveisw.hostevo.com/cd-key-windows-vista.html windows vista screenshots http://xfveisw.hostevo.com/roosters-home-decor.html rustic country home decor http://xfveisw.hostevo.com/alchemist-reflections-special.html alchoholics annonymous meetings http://xfveisw.hostevo.com/used-car-dealer-ships.html used modified cars http://xfveisw.hostevo.com/akademisches-gymnasium-graz.html akai reel to reel tape deck http://xfveisw.hostevo.com/thrillers-audio-books.html audio books books on http://xfveisw.hostevo.com/ampgroup-com-shareholdercentre.html amphetamine dextroamphetamine extended http://xfveisw.hostevo.com/100-free-christian-online-dating.html free online dating for girls http://xfveisw.hostevo.com/allen-county-indiana-small-claims.html allen county indiana warrants http://xfveisw.hostevo.com/dixie-stampede-creamy-vegetable-soup-recipe.html e fagoli soup recipe http://xfveisw.hostevo.com/ahima-american-health-information.html ahista ahista milte hain dil http://xfveisw.hostevo.com/get-cheapest-airline-tickets.html airline ticketing software http://xfveisw.hostevo.com/accounting-salary-in-canada.html accounting software applications http://xfveisw.hostevo.com/affiliate-internet-marketing-online.html affiliate management software http://xfveisw.hostevo.com/akademia-ekonomiczna-wroclaw.html akademia gorniczo hutnicza im st http://xfveisw.hostevo.com/free-christian-books-request-form.html family christian book store colorado http://xfveisw.hostevo.com/beef-rissole-recipes.html beef rissoles recipes

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