In bash script, both of the following usages are valid:
[ $1 != "frps" -a $1 != "frpc" ]
[[ $1 != "frps" ]] && [[ $1 != "frpc" ]]
Which is preferable?
On 04.11.21 06:33, [email protected] wrote:
In bash script, both of the following usages are valid:
[ $1 != "frps" -a $1 != "frpc" ]
[[ $1 != "frps" ]] && [[ $1 != "frpc" ]]
Which is preferable?
The one which is most easily understandable.
On 04.11.2021 09:13, Josef Moellers wrote:
On 04.11.21 06:33, [email protected] wrote:Depending on the actual requirements (portability anyone?), probably
In bash script, both of the following usages are valid:
[ $1 != "frps" -a $1 != "frpc" ]
[[ $1 != "frps" ]] && [[ $1 != "frpc" ]]
Which is preferable?
none of these.
For the first case; POSIX: ">4 arguments: The results are unspecified."
(BTW: Why did you quote the constant literals but not the variables?)
If you don't care about portability and standards use [[...]] .
Many folks forget that we can formulate (even regexp-)comparisons also
with the [standard] 'case' construct
case $1 in (frps|frpc) ;; (*) ... ; esac
The one which is most easily understandable....and which shows the least surprises (generally and in your context).
Janis
On Thursday, November 4, 2021 at 5:40:14 PM UTC+8, Janis Papanagnou wrote:
On 04.11.2021 09:13, Josef Moellers wrote:
On 04.11.21 06:33, [email protected] wrote:Depending on the actual requirements (portability anyone?), probably
In bash script, both of the following usages are valid:
[ $1 != "frps" -a $1 != "frpc" ]
[[ $1 != "frps" ]] && [[ $1 != "frpc" ]]
Which is preferable?
none of these.
For the first case; POSIX: ">4 arguments: The results are unspecified."
(BTW: Why did you quote the constant literals but not the variables?)
Negligence or bad habit of mine :-(
If you don't care about portability and standards use [[...]] .
Many folks forget that we can formulate (even regexp-)comparisons also
with the [standard] 'case' construct
case $1 in (frps|frpc) ;; (*) ... ; esac
Which type of regexp is supported here?
...and which shows the least surprises (generally and in your context).
The one which is most easily understandable.
Janis
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 04:11:05 |
| Calls: | 12,099 |
| Calls today: | 7 |
| Files: | 15,003 |
| Messages: | 6,517,890 |