I want to assign a variable when if statement is true. What's wrong with this assignment?     b = 1 if  3 > 2   File "&lt;stdin&gt;", line 1     b = 1 if 3 &gt; 2                  ^ SyntaxError: invalid syntax
852
If Python does not have a ternary conditional operator, is it possible to simulate one using other language constructs?
15003
Can you add new statements (like print, raise, with) to Python's syntax?  Say, to allow..  mystatement "Something"   Or,  new_if True:     print "example"   Not so much if you should, but rather if it's possible (short of modifying the python interpreters code)
77200
Any idea why echo statement is being executed in both scenarios?  Outputs it worked:  #!/bin/bash  rizwan='' if [ -n $rizwan ]; then   echo "it worked" fi   Replace -n with -z, and it outputs it worked when expecting no output:  #!/bin/bash  rizwan='' if [ -z $rizwan ]; then   echo "it worked" fi
72555
In bash, say you have var=a.b.c., then:  $ IFS=. printf "%s\n" $var a.b.c   However, such a usage of IFS does take effect while creating an array:  $ IFS=. arr=($var) $ printf "%s\n" "${arr[@]}" a b c   This is very convenient, sure, but where is this documented? A quick reading of the sections on  or  in the Bash documentation does not give any indication either way. A search for IFS through  doesn't provide any hints about this effect either.  I'm not sure when I can reliably do:  IFS=x do something   And expect that IFS will affect field splitting.
86352
I'm interesting in directing the output from two commands to a variable.  I don't want the output to be displayed on the screen, but instead assigned to a variable within my script so that I can use it again.  what I am doing is getting the file size from a directory using the commands seen below:  ls -l /var/spool | wc -c   This command gets me the file size in bytes and displays the output as an integer.  I am interested in getting this integer assigned to a variable of my liking so that I can compare it against another variable later  This doesn't seem to work:  size = ls -l /var/spool | wc -c   Would redirection work?   Like this....  ls -l /var/spool | wc -c &gt; size   Either way I want this numeric output to be assigned to a variable and not displayed on the screen.  Any suggestions are very welcomed!
105437
I have problems with my IF command in Google Sheets. If gives #ERROR! all the time. See this simple test:    Not even if I put in the number directly and avoid references:    Am I using the IF wrong? Or what could such a problem be? This example is from a new document.
23695
I am using \if condition in a custom command in my LaTeX document. I would like to know where I can find some good explanation about \if command. I followed a  but it's just an example; there are not any explanation.
55899
I have written a small script to count number of occurrences of logs in a particular file. The following is my code:   #!/bin/sh count=1 while read line do     found=$( grep M $line )     OCCURENCE=$( grep M /log.txt)     if [ "$OCCURENCE" ]; then         echo $count")" $line &gt;&gt; filesave.txt     fi     count=$((count+1)) done &lt; log1.txt   but I am getting this error:  ./count.sh ./count.sh: syntax error at line 10: `found=$' unexpected
7750
Can anybody give a clear explanation of how variable assignment really works in Makefiles.   What is the difference between :   VARIABLE = value  VARIABLE ?= value  VARIABLE := value  VARIABLE += value   I have read the  in GNU Make's manual, but it still doesn't make sense to me.
3625
I have 3 variables like this: $first = 2; $second = 5; $operation = '*';  how can I programaticly assign the solution to this math problem to the $answer variable? I have tried eval(), but that does not work.
119239
I have a variable, x, and I want to know whether it is pointing to a function or not.  I had hoped I could do something like:  &gt;&gt;&gt; isinstance(x, function)   But that gives me:  Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in ? NameError: name 'function' is not defined   The reason I picked that is because  &gt;&gt;&gt; type(x) &lt;type 'function'&gt;
32175
I feel really stupid for asking this, but how do you form more complex if conditionals in TeX? I'm looking for something like:  \ifnum\x=1 OR \ifnum\x=14     {do this} \else     {do that} \fi   I don't want to have to resort to copy-pasting the entire condition just to change the expression when the body is the same.
110271
I am having trouble with bash. I am trying to put a command in an if statement and then compare it to a string.  This works perfectly.  echo $(ipcs | grep Shared | awk '{print $2}')   When I put it in an if statement I get some problems.  $ if [ "$(ipcs | grep Shared | awk '{print $2}')" -eq "Shared"]; then   echo expression evaluated as true; else   echo expression evaluated as false; fi bash: [: missing `]' expression evaluated as false  $ if [ "$(ipcs | grep Shared | awk '{print $2}')" = "Shared"]; then   echo expression evaluated as true; else   echo expression evaluated as false; fi bash: [: missing `]' expression evaluated as false  $ if [ "$(ipcs | grep Shared | awk '{print $2}')" == "Shared"]; then   echo expression evaluated as true; else   echo expression evaluated as false; fi bash: [: missing `]' expression evaluated as false   I tried ==, =, and -eq because I wasn't sure which one to use.
12905
How do you get the  of two variables in Python?  For example, I have two variables that I expect to be strings. I want to test that only one of them contains a True value (is not None or the empty string):  str1 = raw_input("Enter string one:") str2 = raw_input("Enter string two:") if logical_xor(str1, str2):     print "ok" else:     print "bad"   The ^ operator seems to be bitwise, and not defined on all objects:  &gt;&gt;&gt; 1 ^ 1 0 &gt;&gt;&gt; 2 ^ 1 3 &gt;&gt;&gt; "abc" ^ "" Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: unsupported operand type(s) for ^: 'str' and 'str'
86903
If I'm assigning a variable with  temp=$!   what would it be its value?
21288
It seems that   if (x=y) { .... }   instead of  if (x==y) { ... }    is a root of many evils.  Why don't all compilers mark it as error instead of a configurable warning?  I'm interested in finding out cases where the construct if (x=y) is useful.
5320
I tried using this:  $ if [$a == 1] then { echo 'yes'; } fi;   but I get an error:  -bash: syntax error near unexpected token `}'   What is the correct format?  I tried several with no luck.