issue to have "if" inside function

Oct 25, 2011
2
0
Dear sir,

I'm now using your latest TCMD 13.00.27 x64 for evaluation.

The following command runs well, function is defined, and the function is executed
>>function test=`echo done` %+ function test %+ %@test[]
echo done
done

also following conditional command executed well
>>if 1==1 echo done
done

but if i combine them into one function:
>> function test=`if 1==1 echo done` %+ function test %+ %@test[]
if 1==1 echo done

It seems the function is defined as expected, but doesn't have expected result.

Any help from you?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,460
88
Albuquerque, NM
prospero.unm.edu
I'm not sure what you're trying to accomplish with that. The FUNCTION command is used to define, well... functions. Functions return values; they are generally used as arguments to commands. It's pretty rare to have a function return a command as a value.

If you want to create a new command, use ALIAS. If, on the other hand, you want the function to return different values depending on a condition, that's what @IF[] is for.

What are you trying to do?
 
Oct 25, 2011
2
0
I'm not sure what you're trying to accomplish with that. The FUNCTION command is used to define, well... functions. Functions return values; they are generally used as arguments to commands. It's pretty rare to have a function return a command as a value.

If you want to create a new command, use ALIAS. If, on the other hand, you want the function to return different values depending on a condition, that's what @IF[] is for.

What are you trying to do?

What I want do is to deine a function do sth depends on the condition, and finally return a result.
My issue is: if there's an "if" inside function defination, the function can not execuate any futher. here, "echo" is just an example, since it's easy to get the feedback.

I'm not sure if i expressed my idea clearly.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
On Tue, 25 Oct 2011 22:56:45 -0400, justsoso8 <> wrote:

|What I want do is to deine a function do sth and finally return a result.
|My issue is: if there's an "if" inside function defination, the function can not execuate any futher.

It is very difficult and often impossible to execute commands in a function.
Functions should, in general, test/evaluate things and create a string (not echo
it); the function will be replaced by this string when you use it. The best way
to make decisions in a function if with @IF[]. Here's an example.

Code:
v:\> function parity `%@if[%@eval[%1 MOD 2] == 1,odd,even]`

v:\> echo %@parity[3]
odd

v:\> echo %@parity[4]
even

Here's one a little like your original example

Code:
v:\> function test `%@if[%1 == 1,done,not done]`

v:\> echo %@test[1]
done

v:\> echo %@test[2]
not done
 
Similar threads
Thread starter Title Forum Replies Date
G v28 Display Issue Support 7
Jay Sage Issue with CD_ENTER Alias Support 37
Jay Sage Issue with CD_LEAVE Alias Support 3
fpefpe How to? issue with % and evaluation Support 5
cgunhouse Standard User Account Issue Support 2
samintz WAD Display wrapping issue Support 5
M TCC color issue in ConEmu Support 4
samintz Timer issue Support 4
Alpengreis Documentation Minor issue in help file for view /E Support 1
samintz WAD ANSI issue Support 3
D TCSTART issue after reinstallation Support 14
A Documentation [Help file] OPTION "//" synopsis formatting issue Support 0
Chen Touboul Overtyping issue - i press the Insert key, help till press enter for new line in TCC Support 2
Y TCC and Cmder imcompatibility issue Support 7
M Another possibly strange remote registry issue Support 5
T WAD bpokestr issue Support 5
D High-DPI Scaling issue Support 1
S CMDebug 22 issue with del command Support 1
cgunhouse Foldermonitor Issue Support 7
samintz Build 38 Install issue Support 5
rps WAD Setlocal issue Support 4
Luiz Rodrigues Issue with Maven Support 1
Seven Update / install issue with 20.0.20.10.32 take command Support 7
Fross WebDav Drive Mapping Issue Support 19
D Upgrade issue Support 3
Fross V20b8 Everything Issue Support 5
T TCC display issue Support 1
cgunhouse _logfile Issue Support 5
T Fixed Querybox issue Support 1
cgunhouse Fixed Share Memory Issue Support 5
cgunhouse Foldermonitor with "/E" Option Issue Support 6
Fross TabComplete Argument Issue Support 1
fpefpe How to? Stange start up issue Support 1
C cosmetic issue with LIST's (I) Support 9
jbarnes1967 TC 18.00 x64 issue with lua io.popen() Support 2
D How to? Wildcards as sets - looping issue with FOR and REN Support 7
T WAD Free issue Support 6
R Fixed v17.0.54 Tab->COMSPEC Dialog Box Issue Support 2
R Minor Cosmetic Issue in Take Command Window Support 2
cgunhouse One line IFF ... Then ... Else ... EndIFF Statement issue in V17 Support 13
cgunhouse IFTP Path Issue in V17 - Fixed Support 7
S BDEBUGGER issue Support 9
cgunhouse @ISPROC Issue Support 15
cgunhouse TCMD.INI Issue Support 7
T Fixed multi-line alias issue Support 13
R WAD issue with filename completion with system and hidden files Support 8
D Strange issue with FOR loop Support 15
C Install Issue with 3rd Party Privelege Escalation Support 2
W Button command issue Support 5
S XenForo issue Support 8

Similar threads