LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-13-2010, 01:36 PM   #1
flea89
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Rep: Reputation: 0
Unhappy Passing parameters to script -help


Hello. I have the following bash script:

Code:
#!/bin/bash

wget http://www.ceid.upatras.gr/courses/oslab -O s.txt

awk '
{
  for (i=1;i<=NF;i++) {
       if ( $i ~ /[[:alpha:]]@[[:alpha:]]/ )  { 
      print $i      
       }
  }
}' s.txt
which has the name 'extractemails.sh' and works just fine.
However, i whish to be able to give the url http://www.ceid.upatras.gr/courses/oslab (or any other url) as a parameter when i run the script like this:
$ extractemails.sh http://www.ceid.upatras.gr/courses/oslab

what should i change in my code? i have never tried passing parameters
to scripts before so i need some help...
 
Old 03-13-2010, 01:40 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Try this

Code:
#!/bin/bash

wget "$1" -O s.txt

awk '
{
  for (i=1;i<=NF;i++) {
       if ( $i ~ /[[:alpha:]]@[[:alpha:]]/ )  { 
      print $i      
       }
  }
}' s.txt
 
Old 03-13-2010, 01:40 PM   #3
troop
Member
 
Registered: Feb 2010
Distribution: gentoo, arch, fedora, freebsd
Posts: 379

Rep: Reputation: 96
wget "$1" -O s.txt
$1 - first parameter
 
Old 03-13-2010, 01:40 PM   #4
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567

Rep: Reputation: 57
Read section 6. on http://floppix.ccai.com/scripts1.html

You code can easily be modified. Just replace the URL with $1 so it looks like this.

Code:
#!/bin/bash

wget $1 -O s.txt

awk '
{
  for (i=1;i<=NF;i++) {
       if ( $i ~ /[[:alpha:]]@[[:alpha:]]/ )  { 
      print $i      
       }
  }
}' s.txt
 
Old 03-13-2010, 01:47 PM   #5
flea89
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Original Poster
Rep: Reputation: 0
that did the trick ! thank you all
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameters to PERL script paddyjoy Programming 3 03-07-2006 12:04 PM
Passing parameters to a shell script neocookie Linux - General 5 10-20-2005 12:44 PM
Passing parameters to bash script Kamikazee Programming 4 10-01-2005 07:41 AM
passing parameters to functions in shell script kushalkoolwal Programming 1 09-28-2005 03:40 PM
Passing Parameters to Bash Script mooreted Linux - Software 3 04-05-2004 10:08 PM


All times are GMT -5. The time now is 10:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration