Re: Bash: (foo==0)?foo=1:foo=0 valid?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/02/2011 11:30 AM, Robert Nichols wrote:
> On 07/02/2011 12:45 PM, Daniel B. Thurman wrote:
>> I seem to forget my shell programming
>> but is the following statement valid?
>>
>> ($foo==0)?foo=1:foo=0
>>
>> I thought it was called the tristate conditional
>> operator but in any case I could not find it in
>> google.
> You need to enclose the entire expression in double parentheses to make
> bash parse it as an expression.  Plus, your syntax is slightly wrong:
>
>      ((($foo==0)?foo=1:0))
>
> or, since within an expression the '$' to reference a variable is optional:
>
>      (((foo==0)?foo=1:0))
>
> and, if you want to insert the result directly into a command line:
>
>      echo $(((foo==0)?1:0))
> or
>      echo $(((foo==0)?foo=1:0))
>
Thanks - this is good information!
I used:  (((foo==0)?foo=1:0)) and it works in a bash script!

Will add this to my bookmarks! :)

-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux