LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-16-2012, 04:18 AM   #1
dellafaille
LQ Newbie
 
Registered: Jun 2012
Posts: 4

Rep: Reputation: Disabled
Use Variables as a function


hi everyone!
i'd like to use 2 or more variables to create a function.

for exammple

opt1= Find / -type f -name *txt
opt2= 2>/dev/null

$opt1 $opt2 = opt3

$opt3
(now if i do this i only get my opt1 variable and not opt2
is there a way to get them both?)
 
Old 06-16-2012, 04:43 AM   #2
Heraton
Member
 
Registered: Apr 2011
Location: Germany
Distribution: Mint 10, openSuSE
Posts: 58

Rep: Reputation: 3
Smile This should do the trick

Hello dellafaille!

You should use double quoting or even single quoting to make your "functions" strings and then simple catenate them

Code:
#!/bin/bash
opt1="echo 123"
opt2=" > Testfile"

echo "--$opt1----$opt2--"

opt3="$opt1""$opt2"

echo "-$opt3-"
eval "$opt3"

Regards, Heraton
 
Old 06-16-2012, 05:01 AM   #3
dellafaille
LQ Newbie
 
Registered: Jun 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
string has to be at least3 charracter

My god!!! I THANK YOU with all my hearth!!!!
i'm soooooo incredibly happy i finnaly got my breakthrue thank you so much

Quote:
Originally Posted by Heraton View Post
Hello dellafaille!

You should use double quoting or even single quoting to make your "functions" strings and then simple catenate them

Code:
#!/bin/bash
opt1="echo 123"
opt2=" > Testfile"

echo "--$opt1----$opt2--"

opt3="$opt1""$opt2"

echo "-$opt3-"
eval "$opt3"



Regards, Heraton

Last edited by dellafaille; 06-16-2012 at 05:06 AM.
 
Old 06-16-2012, 06:20 AM   #4
Heraton
Member
 
Registered: Apr 2011
Location: Germany
Distribution: Mint 10, openSuSE
Posts: 58

Rep: Reputation: 3
Cool Be my guest...

Hi!

Glad I could help you. I assume your question is solved now. Please mark this thread as solved in your thread options. You might even give reputation by flagging answers useful if you like.

Have fun, Heraton
 
  


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
returning different types of variables from a function knobby67 Programming 3 02-08-2008 08:53 PM
JavaScript: function only taking constants, no variables. :/ RHLinuxGUY Programming 8 01-19-2007 02:49 AM
Utility to find C function defintions, variables, etc... stingerkiss Linux - Software 1 11-19-2006 03:35 PM
accessing variables inside a function bahadur Programming 1 03-27-2005 04:41 AM
Static Variables in C function swifty99uk Programming 4 04-14-2004 10:50 AM

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

All times are GMT -5. The time now is 05:21 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