LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   pass parameters to shell scripts ? (https://www.linuxquestions.org/questions/linux-newbie-8/pass-parameters-to-shell-scripts-79802/)

qwijibow 08-07-2003 06:47 AM

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

irish_rover 08-07-2003 07:23 AM

With bash you can access them with $n. Where 0 is the script itself and 1,2...so on are the arguments passed

cIx 08-07-2003 07:27 AM

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/)


All times are GMT -5. The time now is 03:35 AM.