I am requesting a translation in English words for the first line below/what it does. I think it has something to do with an OR condition. I would like to know exactly.
set /p d=Enter value: || set d=10000
echo %d%
Hello, it's been a while since I've written a serious batch script.
Assuming the script syntax is correct (it looks plausible to me), my English description for the script's behavior would be:
"
Display "Enter value:" to the user and allow them to provide input.
If the user provides input, it is stored in variable "d".
If the user doesn't provide input (presses ENTER without specifying a value), variable "d" is set to 10000.
Finally, the value stored in variable "d" is displayed
"
Explanation:
The script uses logical-OR (||) to simulate an if/else branch construct.
The first line is really two expressions separated by logical-OR:
set /p d=Enter value:
||
set d=10000
With logical-OR, only ONE sub-expression needs to be TRUE (non-zero) for the overall logical-OR expression to be TRUE.
This can lead to so-called "short circuit evaluation", where the script only executes logical-OR sub-expressions until it finds the FIRST TRUE sub-expression.
In your example, "set /p d=Enter value:" is the first sub-expression. If the user enters a value it is stored in "d", but the sub-expression evaluates to a TRUE (non-zero) value (indicating the user entered something). Because a TRUE value logical-ORed with anything is always TRUE, the script won't even bother evaluating the "set d=10000" sub-expression.
If, however, the script evaluates "set /p d=Enter value:" and the user doesn't enter a value, that sub-expression will evaluate to FALSE. This FALSE sub-expression will force the logical-OR expression to evaluate subsequent sub-expression(s) (if any) until it finds one that is TRUE. In your example, the next sub-expression is set d=10000 and so "d" is set to 10000.
In this specific case the result of the logical-OR expression is not used.
In pseudo code, your script could be written as:
DISPLAY "ENTER VALUE:"
INPUT = GET_INPUT()
IF (INPUT IS NOT EMPTY)
{
D = INPUT
}
ELSE
{
D = 10000
}
Good luck and happy scripting