News: Sensation!!! Cialis pills Dicloxacillin Fast acting viagra Crohns phentermine Fiorinal Viagra suppliers Fenoldopam Overnight shipping viagra Diet hcl phentermine pill Taking phentermine with antidepressants Guanethidine Nadolol Order tramadol cod Amoxapine Urine drug testing of tramadol Nitrofurantoin Esomeprazole Corticotropin Pseudoephedrine Natural alternative viagra Digoxin Feldene Side effects of xanax mylan Buy Renova Viagra dangers Womens viagra Lamisil Cialis comparison levivia viagra Clomid o prescription Spiramycin Nabumetone Buy viagra prescription online Phentermine in jonesboro arkansas Colesevelam Fioricet description Encainide Online viagra consultation Nicardipine Weight loss oral hcg and phentermine Pink oval pill 17 xanax identification Canada cialis generic Soma restaurant Herbal phentermine forum Phentermine + sale Uk viagra suppliers Phentermine depression Dichlorphenamide Free pack sample viagra Cheep paris france phentermine Oxycontin Canada cialis Phentermine review Cheap phentermine free consult Phentermine law suits Levivia and viagra Dopamine Phentermine np Viagra patent expiration Alternative to viagra drug Ceftibuten Cefatrizine Viagra sales uk Cheap tramadol online Discount pharmacy phentermine Vicodin withdrawal Drug loss phentermine weight Generic viagra reviews Cialis day next Xanax weight loss Trimetrexate Vinorelbine Viagra sale online Best price for generic viagra Ativan Tramadol apap Add link phentermine purchase suggest Shipping overnight phentermine Drug prescription tramadol Buy phentermine cod Long term effects of phentermine use Purchase xanax online Cyclacillin Zantac Viagra no prescription Cytarabine Ionamin phentermine yellow Nasonex Cortisol Buy com lvivhost online viagra Phentermine in stock Alendronate Phentermine forum Phentermine credit card or cod Discount hydrocodone Cialis drug interactions Pemoline Trovafloxacin Takin prozac and xanax Phentermine no rx needed Viagra free pill Tramadol 50 mg Safety of phentermine Ditropan Cialis versus viagra Xanax online consultation Buy phentermine online no prescription India generic viagra Phentermine xenical diet pill Letrozole Benicar Cefoperazone Online cialis Ansaid Cheap tramadol cod free fedex Phentermine online without a prescription Digitoxin What does xanax do Buy xanax no perscription needed amex accepted Cialis drug prescription Etodolac Viagra price comparison Vicodin m360 Foradil Dalteparin Canadian online pharmacy xanax Home made viagra Gitalin Viagra sale Furosemide Levitra vs cialis vs herbal Glucotrol Viagra by mail Drug laws ohio diet phentermine Inderal Differin Losec Herbal viagra alternative review Allegra Viagra buy in uk online Trileptal 2005 comment december leave viagra Purchase xanax Viagra sample Acitretin Muse Buy fioricet Buy Vicodin Phentermine blue Viagra uses Nifedipine Viagra herbal alternative Viagra from canada Buy viagra in canada Altace Trimethadione Fioricet Lozol Natural phentermine Buy Xenical Phenytoin interaction with xanax Buy viagra 1 Free sample prescription for viagra Buy Lortab Ambien on line Decadron Phentermine us pharmacy online consultation Phentermine gynecomastia Phentermine airborne express Bush inauguration speech draft viagra bastard of Pyridoxine Lipids Buy domain online 199mb com tramadol How much weight will you lose on phentermine Discount soma About phentermine Astemizole Ambien rx Motrin Desmopressin Echothiophate Cheap prescription viagra Aztreonam Zoloft and xanax Promethazine Phentermine drug test Tocainide Ethoheptazine Darvocet Luvox and xanax Liver problems from xanax Singulair Cheap phentermine no rx Buy tramadol online without a prescription Order viagra without prescription Imodium Hydrocodone lortab Ambien Isoproterenol Viagra pictures Buy levivia viagra Citalopram Amitriptyline Chlorcyclizine Overdose xanax Viagra 50mg Phentermine free shipping Phentermine work Soma Cialis soft tabs Viagra price online Isosorbide Cheapest viagra online Free ambien 5 no prescription Prescription soma Buy viagra line Hydrocodone cough Side effects of xanax xr Niacin Xanax without prescription Cheap generic cialis Cytotec Cozaar Divalproex Low dose xanax prosexual Drug testing xanax Hydrochlorothiazide Tramadol hcl acetaminotran Phentermine addiction Exelon Oxycodone Phentermine no perscription required Actos Soma muscle Crestor Abbr href rel title title viagra Dihydrotachysterol Viagra overnight shipping Pulmonary hypertension viagra Order phentermine phentermine online Cheap phentermine perscription Buying viagra online Leflunomide Hydrocodone apap Xanax no prescription needed Finasteride Diphenhydramine Dutasteride Purchase viagra on line Cheapest viagra uk Viagra supplier Diet drug loss phentermine weight Coreg Compare phentermine price Appetite suppressants and phentermine Viagra alternative for women Sample viagra Monopril Tramadol 377 Free viagra without a perscription Sinemet Phentermine and lexapro Beconase Tramadol and online pharmacy Saturday delivery cheapest phentermine Buy cheap domain onlineoutdoorscom xanax Phentermine 15 mg Diovan Impotence treatment viagra Ambien addiction Cheapest generic viagra Lovastatin Anxiety panic disorder xanax On line phentermine Naproxen Dibenzepin Pravachol Chlorpheniramine Hetacillin Ursodiol Viagra cialis comparison Methadone xanax interaction Is phentermine safe Zyban Fastin Vicodin cod Information medical phentermine Order viagra viagra online Cialis experiences How quick can you lose weight with phentermine Methixene Cialis compare levivia viagra Compare levivia viagra Amerge Doxylamine Phentermine picture Liothyronine Phentermine a159 Enoxaparin Meropenem Vicodin detox Quinapril Viagra online cheap Tramadol without prescription Dexamethasone Lasix Depakote Lisinopril with viagra Black market phentermine Liotrix Buy ambien online Viagra online Try viagra for free Olanzapine Quinethazone Phentermine cheapest Phentermine next day delivery Guaifenesin Identify xanax Viagra experiences Adipex meridia phentermine xenical Buy online prescription viagra Free phentermine sample Phentermine 30 mg Potassium Buy Tylenol Clarinex Bacampicillin Atenolol Xanax federal express Buy Adderall Cialis samples Viagra cream Does phentermine really work Guanfacine Zanaflex Phentermine prices Impotence pill viagra Compare levivia and viagra Phentermine low prices Azithromycin Percocet Taking phentermine Xanax death Scopolamine Phenoxybenzamine Generic viagra cialis levitra buy cheap Viagra sample pack Cheapest phentermine Acetaminophen e hydrocodone Cheap cialis Ambien cr effects side Nadolol Lowest viagra price Advair Without prescription phentermine Cialis vs levitra Buy phentermine online same day delivery Hydroxyurea Oseltamivir Canada online pharmacy viagra Tetrabenazine Blindness viagra Phentermine hcl Viagra side affects Viagra online sales Amphetamine Cosopt Losartan Phentermine rx Humulin Ambien side effect Phenylpropanolamine Phentermine drug interaction Minipress Snorting phentermine Apcalis cialis Fluoxetine Canada viagra Ordering viagra Tramadol online Free sample viagra Viagra side effects M357 vicodin Compare phentermine Xanax demerol morphine no prescription needed Dutasteride Diltiazem Phentermine uk suppliers Cialis effective soft tab treatment Generic tramadol Us phentermine Adapalene Phentermine prescriptions online physiphen online Xanax doseage Phentermine order easy Buy online viagra securely Lithium Non perscription generic viagra Cialis story Phentermine shipped to ky Macrobid Phentermine money orders Information about viagra 30mg phentermine Simethicone Viagra online shop Grapefruit viagra Vicodin online Birth defects and phentermine use Omnicef Phentermine ups delivery Online phentermine prescription Diet pal pay phentermine pill Pyridium Nystatin Buy xanax cod Mepenzolate Bricanyl Tramadol overdose Viagra alternatives uk Soma sale Drug tests for xanax Imitrex How fast can you loss weight with phentermine Importing cialis from canada to us Nizatidine Viagra vs levivia Alendronate Tramadol heath solutions network Metaraminol Accupril Cheapest phentermine price Heparin Proguanil Buy in online uk viagra Bupropion Generic viagra pill Lethal dosage of xanax Buy Alprazolam Prazosin Xenical hgh phentermine quit smoking detox Viagra prescriptions online Get phentermine Venlafaxine Meridia 5 90 No perscription generic viagra Remeron Viagra online canada Phentermine faqs Physical symptoms of high blood pressure and xanax Cheapest online pharmacy phentermine Half price viagra Tramadol abuse Cialis levitra viagra vs vs Buy xanax on line Cialis new viagra Diflucan Milrinone Viagra alternate Generic viagra india Xanax bar effects Phentermine success story Cheap phentermine Canadian no phentermine prescription Compare prices tramadol Compare viagra price Drug interactions with cocaine and viagra Phentermine resident sale virginia Lowest price viagra Cephalothin Orlistat Cialis tadalafil L arginine natural viagra Xanax in urine Furosemide Best price viagra Approval cialis Xanax 1mg Ecotrin Zyprexa Buy Acyclovir Soma online pharmacy Cefadroxil Cyclamate Cyber pharmacy viagra Tramadol hydrochloride tablet Hydrocodone effects Phentermine international order Prinivil Tramadol active ingredient Free xanax Alternative new viagra Phentermine discount no prescription Amsterdam holland viagra Mark martin viagra Free viagra online Generic viagra Order phentermine by cod Keppra Aldactone Flexeril Tramadol narcotic Buy cheapest online place viagra Bromocriptine Fluconazole Xanax doses Cheapest online viagra Colestipol Purchase tramadol online Buy cod online phentermine Tools needed for injecting xanax Viagra mexico 5 cheap Imiquimod Discounted phentermine with no prescription Xanax 2 mg Cheap generic viagra substitutes Buy Lipitor Online xanax Phentermine generic Tramadol overnight Paxil Metrizamide Phentermine $89 Estrone Feldene Viagra levivia alternatives Desipramine Cheap viagra online prescription Lowest price for phentermine Albendazole Viagra and blindness Buy vicodin online Bricanyl Cheapest viagra Phentermine sites that ship cash on delivery Is tramadol a narcotic Viagra alternatives Low price phentermine Cialis experience Phentermine priority mail What is viagra Buy viagra now online Viagra cialis levitra Bosch power tools zio lowest viagra Aciphex Xanax bars Viagra conviaindications Discount phentermine price Famvir Reliable same or next day phentermine purchase online Clopidogrel Cialis viagra Lunesta Mixing viagra and cialis Amerge Nasacort aciphex phentermine actos imitrex Phentermine no prescription needed Order tramadol online Constipation phentermine Liquid cialis Buy phentermine prescription Diet phentermine pill Berman sister female viagra study Actos phentermine aciphex imitrex Buy phentermine epharmacist Thiabendazole Loperamide Hydrocodone prescription Xanax withdrawl symptoms Phentermine blue capules Free phentermine Cialis tablets 99 phentermine Herbal alternatives to viagra Cheap quality viagra Cheap phentermine online Methylphenidate Mexico viagra Viagra prescriptions What is xanax Herbal viagra affiliate Tramadol hcl acetaminotran par Felbamate Levoxyl Low cost phentermine Phentermine for sale Allopurinol What do xanax look like Buy cialis viagra Buspirone Buy discount phentermine Sell viagra Danaparoid Buy viagra on line Lose weight with phentermine and 5 htp Information on phentermine Brompheniramine Phentermine hoodia diet pill Clarithromycin Line pharmacy phentermine Amphetamine Adipex diet phentermine pill prescription Cleocin Coumadin Levivia vs viagra Mark martin uniform jacket team caliber viagra Lorazepam Loxapine Phentermine 90 Norvasc Ethinamate Anafranil Free try viagra Female herbal viagra Fill viagra prescription Ephedrine Neomycin Diovan Generic viagra online Metoclopramide Sophia viagra Phentermine side effects dangers Buy cheap vicodin Viagra levivia Zileuton Tussionex Sotalol Cheap phentermine canada Fosamax 180 tablet tramadol Cheap xanax online Is viagra safe for woman Metformin Neurontin Viagra paypal france Buy herbal viagra Hyzaar Losec Reglan Cialis lowest price Cialis Oxycodone Viagra lowest prices Ethotoin Piperidolate Inject xanax Alternative to viagra online Kanamycin Vicodin for sale Book hydrocodone sport Viagra for sale online Atrovent Phentermine diet pills cheap Buy Zyban Buy Effexor Online consultations and prescriptions phentermine Phentermine warning Benzthiazide Buy cod diet phentermine pill Nicorette Xanax and alcohol Pantoprazole Lexapro Zalcitabine Xanax interaction with paxil Low natural resources for the drug phentermine Naprosyn Long term phentermine use Purchase fioricet Buy cialis without prescription Viagra alternates Overnight viagra Methotrexate Carisoprodol Cialis online Buy xanax without prescription in usa Diethylpropion Methylphenidate Tramadol and dosage Bromodiphenhydramine Cheapest viagra prices Approval cialis fda Vicodin withdrawal symptom Long term side effects of phentermine Tramadol cheap Phentermine wholesale Viagra use Lexapro Cheapest viagra on line Generic xanax xr Generic price viagra Cause rebound weight gain phentermine Ciclopirox Levlen Cheap tramadol Woman use viagra Dothiepin Ceftazidime Phentermine vs phentrazine Phentermine prescriptions online Labetalol Liqued viagra Black market costa rica pharmacy phentermine no imprint code Ketoconazole Phentermine compare prices Cheep phentermine with cod payments Xanax information Arava Aprotinin Meclofenamate Tramadol sales Vicodin Ethopropazine Combivent Cialis western open Chlorthalidone Ofloxacin 5 mg no prescription Phentermine hormone Ceclor Indomethacin Difference between valium and xanax Macrobid Indinavir Meperidine Ambien overnight Xanax overdose Tramadol cod Oxycontin Buy cod pay phentermine Tramadol sale On line pharmacy phentermine Cialis levivia viagra vs vs Genaric viagra Fluconazole Free online phentermine shipping Cheap phentermine diet pills Amaryl First viagra commercial network tv Meprobamate Phentermine adipex diet pill discount Phentermine lose weight loss diet pills Nortriptyline Cheapest phentermine pill Free viagra prescription Phentermine interactions Lozol Oxaprozin Phentermine by cod Effects of viagra on woman Adalat Ativan re valium vs vs xanax Levivia viagra vs Dextroamphetamine Submit a site viagra Xanax drug interactions Phentermine cheap no prescription Wholesale pfizer viagra Tolazoline Diphenadione Diet ky phentermine pill ship that Xanax depression Phentermine and methamphetamine Fioricet medication Generica viagra Tramadol 50mg Soma sleep Opipramol Lanoxin Cheap price on phentermine Lisinopril versus viagra Spironolactone Imipenem Free shipping on phentermine diet pills Xanax mg Why phentermine Long term side effects of xanax Viagra buy viagra Clindamycin Viagra samples Ramipril Buying viagra on line Maxzide Cheapest prescription viagra Tramadol drug interactions Buy cialis viagra How does xanax work Amiodarone Viagra for woman Phenylbutazone Lodine Lactulose Phentermine discover card Tramadol information Crestor Adalat Online phentermine prescriptions Where to buy phentermine online Strattera Seroquel Cialis free trial Buy online order viagra Prozac interact xanax Estrogen Laetrile Cod hydrocodone Online pharmacy and phentermine overnight Buy online phentermine shipping Ketorolac Phentermine and glaucoma Hydrocortisone Tacrolimus Glipizide Good morning viagra commercial 50mg viagra Nicorette Catapres Tramadol dog Loratadine Ibutilide Using viagra Discount phentermine to florida Cephalexin Glycerin Xanax drug testing Free overnight phentermine shipping Klonopin xanax Phentermine cheapest price Dulcolax Minipress Xanax withdrawel Levitra cialis info Abacavir Buy Codeine Buy viagra order viagra Ibuprofen Tramadol dosage for dogs Compare ionamin phentermine Iv sample viagra Prozac Buy ambien Xanax anxiety relief pills order here Generic cialis Tramadol saturday delivery Cialis dose Zithromax Clomiphene Viagra for sale Estradiol What happens when women take viagra Tramadol hydrochloride Nitroglycerin Buy prescription viagra Effects phentermine side strong Hexachlorophene Overnight xanax or alprazolam delivery Butoconazole Link buy online viagra info domain Relafen Buy soma Does xanax show up on drug tests Ceftin Herbal substitute viagra Alternative herbal viagra Ethionamide Digitalis Diet diet dieting phentermine pill Ecotrin Hydroflumethiazide Canada xanax Prescription phentermine with cod payment Buy cheap cialis online Concomitant use of cialis and levitra Fioricet order Alternative to viagra Tramadol pharmacy Pepcid Hydralazine Fioricet phentermine shipping Hydrocodone vicodin Online viagra sales Viagra 6 free samples Sell viagra online Isoflurophate Viagra prescription online Cheapest phentermine online Botox Phentermine mexican pharmacies online Macrodantin Herbal phentermine side effects Nizoral Somatostatin Phentermine yellow 30 mg Dosages xanax Online xanax prescription Viagra cost Purchase phentermine online Cheapest place to buy phentermine online Xanax withdrawals Buy cheap soma Discount xanax Cod tramadol money orders Lethal doses klonopin wellbrutrin xanax Triamterene Phentermine studies Cash on delivery phentermine Phentermine ionamin Linezolid Buy Norco Vicodin prescription Phentermine no prescription required next day delivery Discount online viagra 5 free shipping Discount viagra online Vicodin side effects Capreomycin Cialis vs viagra Long term side effects from xanax Buy Diflucan Oxymorphone Ordering 30mg phentermine Phentermine 37 5mg shipped to kentucky Viagrafix corporation Bulk phentermine Cialis comparison levitra viagra Lexapro interaction with phentermine Cod online pharmacy phentermine sell Polythiazide Buy viagra pill online Buy online prescription viagra without Terbinafine _achetez le viagra de levivia History of phentermine use Order phentermine online without perscription Viagra soft tabs Xanax pills Online pharmacies phentermine xenical meridia Order phentermine cod online Phentermine withdrawal Tramadol hcl tab Oxyphenbutazone Xanax dosage Diet phentermine Moexipril Norvasc Lidocaine Phentermine pharmacy Cheapest phentermine diet pills 2 mg xanax Cod free phentermine shipping Furazolidone Viagra prescription uk Meridia sibutramine Lisinopril Xanax withdrawal effects Diet online phentermine pill purchase Clorazepate

Calling external programs

* Piping. e.g., only list files beginning with foo: ls | grep foo*
* Redirecting output. There are several ways to do this.
o ls > foo overwrites foo with the output of ls
o ls ยป foo adds the output of ls to the end of foo
o ls 2> foo overwrites foo with STDERR output of ls
o ls &> foo overwrites foo with the output of ls and STDERR output of ls
o ls 1>&2 redirects STDOUT of ls to STDERR
o …
* Chaining. First, note that by convention C programs return a 0 to indicate successful exit status, e.g.,

#include
int main(int argc, char *argv[]) {
printf(”Hello World!\n”);
return 0;
}

But a nonzero exit status indicates an failure of some kind. There are operators in Bash that use the exit status. For example, cmd || echo “error message” generates an error message if cmd fails. Also, make foo && ./foo runs foo only if the make is successful. In general, there are two ways to chain commands: (1) cmd1 || cmd2 || … || cmdn; executes until cmdi has given a nonzero return value and, (2) cmd1 && cmd2 && … && cmdn; executes until cmdi has given a zero return value.
* Sequencing. e.g., cmd1; cmd2 executes cmd1 first and cmd2 second regardless of exit status.

Hello World!
Save the following in hw.sh.

#!/bin/bash
echo Hello World

The script must have the execute permission set before it is run. Execute the file by running the following at the Bash prompt.

# chmod u+x hw.sh; ./hw.sh
Hello World!

Command-line arguments and variables
Command-line parameters provide one way for the script to access data from the shell. These reserved parameter variables start with the name of the script, $0, and are assigned positionally for each argument $i. The number of parameters is set in $#. The script below simply prints its first two arguments.

#!/bin/bash
echo $1
echo $2

The example below shows how the programmer can define variables. The variable $STR is assigned the value “argument 1: ” and then concatenated to the command-line parameter $1.

#!/bin/bash
STR=”argument 1: ”
echo $STR$1 #concatenate $STR with $1

The script prints out its first command-line argument.

# ./hw2.sh “Hello World!”
argument 1: Hello World!

There are a few general notes about user-defined variables like $STR in the above example.

* Variables can simply be used without any explicit introduction.
* Changes to variables within a script are not visible outside the script, e.g.,

# STR=”original string”
# ./hw2.sh
argument 1: Hello World!
# echo $STR
original string

* The export command makes variables visible to subscripts, but not outer scripts, e.g., suppose script s1.sh uses the variable $STR.

# export STR=”original string”
# ./s1.sh # s1.sh will see STR=”original string”

* Several built-in variables are set by the shell, e.g, PATH, HOME, etc.
* The command set prints all defined variables.
* Variables are assumed to be strings by default. Casting is applied when necessary.

Arithmetic Expressions
The straightforward way of performing arithmetic does not work as expected, e.g.

# x=1+2
# echo $x
1+2

Instead, use the double parens to perform arithmetic.

# (( i=1 ))
# (( j=$i+1 ))
# echo $j
2

Conditionals
There are several forms for branching, the simplest of which uses if statements. This script tests whether there are more than one command-line arguments.

#!/bin/bash
MIN_ARGS=1
if [ “$#” -lt “$MIN_ARGS” ]; then
echo There are more than one command-line args
else
echo Fail
fi

The following script tests to see if FILE exists and is a file that is neither directory nor device file, called a “regular file”.

#!/bin/bash
FILE=”foo”
if [ -f $FILE ]; then
echo FILE foo is a regular file
fi

Looping
The for loop is very useful, and has several forms, e.g., this prints three strings

#!/bin/bash
for v in one two three; do
echo $v
done

When run:

one
two
three

This example prints out a directory listing.

#!/bin/bash
for v in $( ls ); do
echo item: $v
done

When run:

item: foo1
item: foo2
item: foo3

C-style loops are also available.

#!/bin/bash
N=3
for (( i=1; i echo item: $i
done

When run:

item: 1
item: 2

The while loop is also available.

#!/bin/bash
i=1
LIMIT=3
while [ “$i” -lt “$LIMIT” ]; do
echo item: $i
(( i++ ))
done

When run:

item: 1
item: 2

Exercise
Write a bash script in the file mycat.sh that takes 2 or more arguments (call them f1, f2, … fn). Follow these guidelines.

* All arguments are filenames.
* If fewer than two arguments are given, an error message is printed to STDERR.
* If the file f1 exists (test by -e), an error message is printed to STDERR.
* If some files in f2, …, fn are not regular files, then print an error message to STDERR at the end, displaying each missing file at once. For example, if files foo1 and foo2 are missing, print “ERROR: missing files foo1, foo2”.
* Otherwise, concatenate files f2, …, fn using cat, and store the result in f1

Run some test cases to be sure the solution is correct. Say we have files f2,

foo1
foo2

and f3.

foo3
foo4

Then, ./mycat.sh f1 f2 f3 should output the following into f1.

foo1
foo2
foo3
foo4

Test your script for the error cases, e.g, having f1 exist, or having f2 not exist.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists