[Techtalk] Bash functions with user-defined parameters
Sue Stones
suzo at bigpond.net.au
Tue Apr 29 00:15:51 EST 2003
I haven't done any bash shell scripting, but my guess would be to make another
variable so that you end up with:-
#!/bin/bash
myfunction()
{
$num1 = $1
while [ $num1 -le $2 ]
do
echo $num1
#problem here...$(( $num1 + 1 ))
done
}
On Mon, 28 Apr 2003 10:52 pm, Berenice wrote:
> I've been messing around with bash and want to create a function that
> takes two different integers and increments the first integer by 1,
> until the first integer is the same as the second integer. Eg: if
> there are 2 numbers, 1 and 4, add 1 to the first number until it
> becomes 4.
>
> Now I can do this interactively like this:
>
> #!/bin/bash
> echo "Enter 2 numbers:"
> read num1 num2
> while [ $num1 -le $num2 ]
> do
> echo $num1
> num1=$(( $num 1 + 1 ))
> done
>
> But I'm having trouble making it into a function that executes by
> typing the function name with parameters, eg: myfunction 1 4. Here's
> what I've done so far:
>
>
> #!/bin/bash
> myfunction()
> {
> while [ $1 -le $2 ]
> do
> echo $1
> #problem here...$(( $1 + 1 ))
> done
> }
>
>
> The problem is with the $(( $1 + 1 )) because you can't do $1=$(( $1
> + 1 )). Is there a way to fix this, or should I forget about using
> $1 and $2?
>
> Thanks
> Berenice
>
>
>
>
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
> _______________________________________________
> Techtalk mailing list
> Techtalk at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/techtalk
More information about the Techtalk
mailing list