LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-11-2009, 07:39 AM   #1
mitramcc
LQ Newbie
 
Registered: Feb 2009
Posts: 3

Rep: Reputation: 0
Bash: Problem to run a function in Case


#!/bin/bash

getMatches (){
str=( $2 )
pattern=$3

sizePat=${#pattern}
let x=$sizePat-1
for (( i=0 ; i<${#str[*]} ; i=i+1 ))
do
for (( j=0 ; j<${#str[${i}][*]} ; j=j+1 ))
do
if [ ${str[${i}]:${j}:${j+$sizePat}} = $pattern ];
then let x=x+1
var[${i}]=${str[${i}]}
let i=i+1
let j=-1
let x=$sizePat-1
fi
done
done
echo "var "${var[*]}
}
cmd=$1
case $cmd in
-r)
getMatches $1 $2 $3;;
*)
getMatches x 'asd qwe asd1 asd2' as
esac


if I run:
./script.sh -r 'asd qwe asd1 asd2' as
the variable var is empty,
but if I run:
./script.sh
the resul is:
var asd asd1 asd2

how can I give the arguments throw the console? anyone can help me?
thx




I HAVE SOLVED THE PROBLEM ALREADY... thx... i was declaring the variables inside the function :/

Last edited by mitramcc; 02-11-2009 at 08:39 AM.
 
Old 02-12-2009, 02:07 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
and to stop bouncing: the OP has solved the problem
 
  


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
not calling function inside switch case??? sarathius Programming 2 01-29-2008 10:38 AM
how to call a function inside switch case sarathius Programming 4 01-28-2008 05:36 AM
How do I run a function within a function arguement? C/C++ RHLinuxGUY Programming 12 05-19-2006 02:29 PM
Bash looping or function within a function FirmbIT Programming 2 04-24-2006 01:06 PM
system() function in nested if else/case! natalinasmpf Programming 10 01-26-2004 06:52 AM

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

All times are GMT -5. The time now is 04:56 PM.

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