LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Use Variables as a function (https://www.linuxquestions.org/questions/linux-newbie-8/use-variables-as-a-function-4175411746/)

dellafaille 06-16-2012 04:18 AM

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

Heraton 06-16-2012 04:43 AM

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

dellafaille 06-16-2012 05:01 AM

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 (Post 4704694)
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


Heraton 06-16-2012 06:20 AM

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


All times are GMT -5. The time now is 05:32 AM.