nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

How to pass a parameter to a shell script

This is a discussion on How to pass a parameter to a shell script within the Shell scripting forums, part of the Development/Scripting category; I have 2 scripts, ftp_file.sh and sendfile.sh ftp_file.sh ~~~~~~ #!/bin/bash sftp -b /home/<instance>/script/ftp/sendfile.sh oracle@<host> sendfile.sh ~~~~~~~ #!/bin/bash cd /u01/<destination_directory> put ...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-23-2008, 09:49 PM
Junior Member
User
 
Join Date: Jul 2008
OS: red hat
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
flyingrat is on a distinguished road
Default How to pass a parameter to a shell script

I have 2 scripts, ftp_file.sh and sendfile.sh

ftp_file.sh
~~~~~~
#!/bin/bash
sftp -b /home/<instance>/script/ftp/sendfile.sh oracle@<host>

sendfile.sh
~~~~~~~
#!/bin/bash
cd /u01/<destination_directory>
put /d01/<source_directory>/xxx.out xxx.out

When i run ./ftp_file.sh the sendfile.sh is executed and the xxx.out file is transferred from the source_directory to the destination_directory. This works fine. The sendfile.sh is hardcoded with xxx.out. How can i pass a parameter to sendfile in order to transfer other files to the destination_directory instead of just xxx.out? I am new to shell scripting.

regards
flyingrat
Reply With Quote
  #2 (permalink)  
Old 07-24-2008, 01:34 AM
amitabh's Avatar
Contributors
User
 
Join Date: Jul 2008
Location: New Delhi
OS: FreeBSD
Posts: 98
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Power: 4
amitabh has a spectacular aura about amitabh has a spectacular aura about amitabh has a spectacular aura about
Send a message via MSN to amitabh Send a message via Yahoo to amitabh Send a message via Skype™ to amitabh
Default

Examples of passing arguments to the shell
Example of using the shift command
Reply With Quote
  #3 (permalink)  
Old 07-24-2008, 03:14 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Posts: 2,658
Thanks: 11
Thanked 237 Times in 177 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Code:
#!/bin/bash
cd /u01/<destination_directory>
put /d01/<source_directory>/$1.out $2.out
$1 is first parameter
$2 is second parameter

sendfile.sh file1 file2 will transfer as
Code:
put /d01/<source_directory>/file1.out file2.out
HTH
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #4 (permalink)  
Old 07-24-2008, 03:01 PM
Junior Member
User
 
Join Date: Jul 2008
OS: red hat
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
flyingrat is on a distinguished road
Default

Thanks! It worked.

Regards
flyingrat
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Increasing the KERNEL parameter sathiya Ubuntu / Debian 4 02-01-2008 11:36 AM
writing a shell script to find out my shell name jaymob123 Shell scripting 1 10-08-2007 01:36 AM
SED pass a output line to another cillo Shell scripting 6 11-01-2006 02:59 PM
user pass word sparky Shell scripting 1 06-26-2006 08:19 PM
How to pass shell variable to awk program Shell scripting 4 06-23-2006 06:11 AM


All times are GMT +5.5. The time now is 01:13 AM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38