LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 08-07-2003, 06:47 AM   #1
qwijibow
LQ Guru
 
Registered: Apr 2003
Location: nottingham england
Distribution: Gentoo
Posts: 2,672

Rep: Reputation: 47
pass parameters to shell scripts ?


Hi guys.

how do i pass a parameter to a shell script, in a way that the shell script will then pass that parameter to an executable ???

thanX
 
Old 08-07-2003, 07:23 AM   #2
irish_rover
Member
 
Registered: Sep 2002
Location: IN, USA
Distribution: Debian, Endian FW
Posts: 368

Rep: Reputation: 30
With bash you can access them with $n. Where 0 is the script itself and 1,2...so on are the arguments passed
 
Old 08-07-2003, 07:27 AM   #3
cIx
Member
 
Registered: Aug 2003
Location: /dev/null
Posts: 40

Rep: Reputation: 15
suppose you have the shell script test.sh

test.sh:

#!/bin/sh

echo "you passed the parameter $1";

now execute the file

./test.sh hello

this will print you passed the parameter hello

to pass it to other programs:

#!/bin/sh

echo "parameter $1"

/usr/bin/find $1

now, when you execute

$./test.sh \/etc\/
it will print parameter /etc/
and then execute 'find' with the parameter /etc/ (will display all the files in /etc/)
 
  


Reply



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
shell: positional parameters... neidias Programming 1 04-04-2005 02:45 PM
How to pass on boot parameters Slack 10.1 tdking19 Slackware 3 03-21-2005 10:41 AM
Pass Parameters to php from bash iman00b Linux - Newbie 2 09-09-2004 05:30 PM
how do I pass special parameters to the kernel at startup? Falafel Fedora 4 01-19-2004 06:49 PM
howto pass parameters to modules Sammy2ooo Linux - Software 5 07-01-2003 08:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:16 AM.

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
Open Source Consulting | Domain Registration