Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 4th November 2005, 01:58 PM
tonytiger Offline
Registered User
 
Join Date: Jun 2004
Posts: 168
How to give script a parameter?

Hi. I'm wondering is it possible to give script a parameter and how to use it? Let's say I'd like to print out the parameter I give when executing the script. So the script file would be something like:
Code:
#!/bin/sh -v
# Get the parameter.
echo "$parameter"
And I'd like to run this with command (if the script is named test):
Code:
./test -parameter
Hope you understand what I mean.

So is this possible? If so, then how?

Thank you.

Tony
Reply With Quote
  #2  
Old 4th November 2005, 02:50 PM
homey Offline
Registered User
 
Join Date: Feb 2005
Posts: 415
Do you mean something like this?

./test one two three
Code:
#!/bin/bash
echo this is $0
echo this is $1
echo this is $2
echo this is $3
Reply With Quote
  #3  
Old 4th November 2005, 03:09 PM
tonytiger Offline
Registered User
 
Join Date: Jun 2004
Posts: 168
Not actually.
I'll try to explain a little bit more.
I'd like to give the script a parameter which could be used then in the script. Idea would be similar as using functions (object etc.) with paramters in normal programming languages.

My actual problem is that I need to update file using scp. However the name of the updated file differs everytime. So instead of writting
Code:
scp file.html username@server.com:directory/subdirectory/webpage.html
everytime, I' d like to create a script which takes file.html as parameter and executes the scp ... command with the given file.html.

Tony
Reply With Quote
  #4  
Old 4th November 2005, 03:19 PM
homey Offline
Registered User
 
Join Date: Feb 2005
Posts: 415
scp is going to want a password.

./test file
Code:
scp $1.html username@server.com:directory/subdirectory/webpage.html
Reply With Quote
  #5  
Old 4th November 2005, 03:19 PM
JordanN Offline
Registered User
 
Join Date: Sep 2004
Location: Fort Wayne, Indiana
Posts: 573
$1 is reserved for the first parameter after the script name
$2 is the second
$n is the nth

ie: myscript.sh parameter1 parameter2

Last edited by greenlead; 4th November 2005 at 07:21 PM.
Reply With Quote
  #6  
Old 4th November 2005, 05:37 PM
tonytiger Offline
Registered User
 
Join Date: Jun 2004
Posts: 168
Ah. Ok. Didn't catch you at the first time homey. Thank you both.

Tony
Reply With Quote
Reply

Tags
parameter, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
this script to give the user te ability to mount/umount new Partitions fast. mohamednasr2000 Guides & Solutions (No Questions) 2 31st October 2007 09:35 AM
Unknown parameter CoastingSpeedThreashold georges_dib Using Fedora 1 9th November 2006 03:54 PM
How to open url with parameter with JavaScript? tonytiger Wibble 8 9th April 2005 05:26 PM


Current GMT-time: 15:37 (Thursday, 23-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat