
bash - Using expr, $(()), (()) - Unix & Linux Stack Exchange
expr can do this without a pipe: if expr november : nov then : do something fi the only catch is expr works with anchored strings, so if you want to match after the beginning you need to change the REGEXP: if expr november : '.*ber' then : do something fi Regarding (( )), this construct is not POSIX, so should be avoided.
Adding two numbers using expr - Unix & Linux Stack Exchange
2012年8月8日 · expr is an external program used by Bourne shell(i.e. sh). Bourne shell didn't originally have any mechanism to perform simple arithmetic. It uses expr external program with the help of backtick. The backtick(`) is actually called command substitution . Command substitution is the mechanism by which the shell performs a given set of commands ...
Understanding of the regexp match feature of the expr utility
2022年4月11日 · What is expr doing in these two commands? For the first command, it seems expr found a match from the first character of abc and reports the matched length. But why does it produce 0 for the second command?
shell - Parenthesis in expr arithmetic: 3 * (2 + 1) - Unix & Linux ...
2014年8月13日 · Furthermore, expr needs each number and operator to be passed as a separate parameter. Thus: expr 3 \* \( 2 + 1 \) Unless you're working on an antique unix system from the 1970s or 1980s, there is very little reason to use expr. In the old days, shells didn't have a built-in way to perform arithmetic, and you had to call the expr utility
scripting - What is the difference between bcl and expr? - Unix
2016年12月1日 · For one thing, bc supports big numbers while expr tops out at 2^63-1: $ expr 9223372036854775807 + 1 -9223372036854775807 $ echo "9223372036854775807 + 1" | bc 9223372036854775808 bc also has exponentiation and square …
Substring extraction with expr - Unix & Linux Stack Exchange
2015年12月2日 · man expr says the "STRING : PATTERN" expression is "anchored", and then in the info page (info coreutils 'expr invocation') you can read: `STRING : REGEX' Perform pattern matching. The arguments are converted to strings and the second is considered to be a (basic, a la GNU `grep') regular expression, with a `^' implicitly prepended.
expr: unexpected operator - Unix & Linux Stack Exchange
2020年10月18日 · Stack Exchange Network. Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
'expr: syntax error: unexpected argument' - result from alias
2019年9月2日 · expr: syntax error: unexpected argument ‘2’ expr: syntax error: unexpected argument ‘2’ I wanted to output a file called results_a_b where a and b are values defined in counting the files in folders defined in the alias, but instead the command outputs results__
string - Zsh equivalent of bash's `expr index ... - Unix & Linux Stack ...
2018年7月31日 · However, there are two reasons why this doesn't work exactly the same as expr index: In the example you gave, you are searching for xyzd, which is not present in your string, but since your string ends in xyz, expr gracefully drops the 'd' and returns a match. One might argue that the behaviour of Zsh is more reasonable in this respect, but of ...
expr and variables - Unix & Linux Stack Exchange
It works fine for input arguments like 1 + 2, but it does not work properly (or, more likely, at all: expr: syntax error) for asterisk (star) symbol. I'd like to know why this does not work as desired and how should I fix this. Script like this: expr "$@" does work - I just do not understand what is going on when I assign $@ to a variable.