nixCraft Linux Forum

nixCraft

Linux 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 ...


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

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 07-23-2008, 09:49 PM
Junior Member
User
 
Join Date: Jul 2008
My distro: red hat
Posts: 2
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
Sponsored Links
  #2 (permalink)  
Old 07-24-2008, 01:34 AM
amitabh's Avatar
Contributors
User
 
Join Date: Jul 2008
Location: New Delhi
My distro: FreeBSD/OpenBSD
Posts: 68
Rep Power: 3
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
My distro: Ubuntu
Posts: 1,061
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 | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #4 (permalink)  
Old 07-24-2008, 03:01 PM
Junior Member
User
 
Join Date: Jul 2008
My distro: red hat
Posts: 2
Rep Power: 0
flyingrat is on a distinguished road
Default

Thanks! It worked.

Regards
flyingrat
Reply With Quote
Reply

Bookmarks


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 On

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 02:37 AM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

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