zsh ternary operator syntax help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting zsh ternary operator syntax help
# 1  
Old 05-14-2009
zsh ternary operator syntax help

Hi,

Can someone give me an example of how to use zsh's ternary operator?

I tried:

# a=1
# c=( a ? "true" : "false" )


and got:

zsh: no matches found: ?

I'm running zsh 4.2 on RHEL AS 4.

Thanks!

Paul
# 2  
Old 05-14-2009
It is supported with arithmetic evaluation:

Code:
% print $((1?1:0))          
1
% print $((0?1:0))
0

... and in conditional substrings in prompts with different syntax:

Quote:
%(x.true-text.false-text)
Specifies a ternary expression. The character following the x
is arbitrary; the same character is used to separate the text
for the `true' result from that for the `false' result. This
separator may not appear in the true-text, except as part of a
%-escape sequence. A `)' may appear in the false-text as `%)'.
true-text and false-text may both contain arbitrarily-nested
escape sequences, including further ternary expressions
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can I do this without eval? (zsh)

I have in one shell variable, op, a string which represents a "test operator" in a ] construct, for instance -d or -n or -s, an in another shell variable, arg, some arbitrary string. What I want to achieve, is basically this: #This is INCORRECT code. I just want to get you the idea, what I'm... (7 Replies)
Discussion started by: rovf
7 Replies

2. Shell Programming and Scripting

Getting syntax error with awk ternary operator

split($7,a," "); date = a; time = a split(date,d,"/"); month = sprintf("%02d",d); day = sprintf("%02d",d); year = 2000 + d % 100 split(time,t,":"); hour=t; min=t hour >= 12? { hour=hour-12; amPm=" PM" } : amPM=" AM" hour == 0? hour=12 time=sprintf("%02d",hour)":"sprintf("%02d",min)amPm ... (4 Replies)
Discussion started by: Michael Stora
4 Replies

3. UNIX for Dummies Questions & Answers

syntax error: invalid arithmetic operator

hi, i have a bash script that i want to receive a a string from another bash file. But because the string has a dot in the middle it gives me an error. The error is in this line: let valor=$1 and the value passed is rules.txt the error is: let: valor=rules.txt: syntax error: invalid... (2 Replies)
Discussion started by: limadario
2 Replies

4. Shell Programming and Scripting

Using zsh

Hi all i am forced to use tcsh at work but i want to use zsh, so i have added this to my .cshrc if (! $?STARTTCSH) then if ("$tty" != "" && -x /bin/zsh) exec /bin/zsh exit endif but this now stopped me going back to tcsh if i need to, is there a way to do this, i would... (7 Replies)
Discussion started by: ab52
7 Replies

5. Shell Programming and Scripting

OR operator syntax question in AWK script

Hi guys, I confused about syntax used in OR script as follow: I have this sample file separated by "|" containing: January|Month No. 1 February|Month No. 2 March|Month No. 3 April|Month No. 4 May|Month No. 5 June|Month No. 6 July|Month No. 7 August|Month No. 8 September|Month No. 9... (11 Replies)
Discussion started by: cgkmal
11 Replies

6. Shell Programming and Scripting

syntax error in shell test: unknown operator

Hi All, can some one figure out the syntax issue here. How to overcome this? #!/bin/sh $ HFR_MAIL=NO $ PRP_MAIL=NO $ MC_MAIL=NO $ if && && ]; then > echo "NO " > else > echo "YES" > fi test: unknown operator NO $ if && && ]; then > echo "NO" > else > echo "YES" >... (4 Replies)
Discussion started by: shellscripter
4 Replies

7. UNIX for Dummies Questions & Answers

question about zsh

hi, In bash, $ bind -P | grep yank-last yank-last-arg can be found on "\M-.", "\M-_". this allows me to press ALT key and the period (.) to yank the last argument of the previous command line into the current command line. How can I get the same behavior in zsh ? Thanks ... (0 Replies)
Discussion started by: Andrewkl
0 Replies

8. Shell Programming and Scripting

syntax error: `-a' unexpected operator/operand in IF

When i tyr this, it gives me a syntax error...i tried removing quotes,removing spaces,replacing -eq with '='.. Can somebody suggest that is the problem? if ]; then (4 Replies)
Discussion started by: dba.admin2008
4 Replies

9. Programming

ternary operator

How do I interpret the following ternary operation? fn_max(var_type a,var_type b,var_type c) { var_type t; return(t=((t>a?:t;a)>b)?:t;b)>c?:t;c) } Thanks (1 Reply)
Discussion started by: naan
1 Replies

10. Shell Programming and Scripting

tutorials about zsh

hi there I'm looking for tutorials about zsh (beginners to experts) can you give me addresses please? thx a lot (3 Replies)
Discussion started by: SpY974
3 Replies
Login or Register to Ask a Question