[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ ! ! hey ] -> [: too many arguments
From: |
Steffen Nurpmeso |
Subject: |
Re: [ ! ! hey ] -> [: too many arguments |
Date: |
Fri, 24 Jun 2022 17:00:29 +0200 |
User-agent: |
s-nail v14.9.24-259-ge9cf982228 |
Greg Wooledge wrote in
<YrT2m2dIlQQaEe+z@wooledge.org>:
|On Thu, Jun 23, 2022 at 05:58:23PM -0400, Chet Ramey wrote:
|> On 6/23/22 5:08 PM, Steffen Nurpmeso wrote:
|>> bash -c 'if [ ! ! hey = hey ]; then echo du; fi'
|
|> Sure. This one isn't a common idiom for shell programmers, apparently.
|
|I've seen it used in a math context, inside PS1. Like so:
|
|color=(
| "$(tput setaf 2)" # 0 = green
| "$(tput setaf 1)" # 1 = red
|)
|normal="$(tput sgr0)"
|PS1='\[${color[!!$?]}\]$?\[$normal\] \h:\w\$ '
|
|This writes the previous command's exit status in either green or red.
|It "smashes" all nonzero exit codes to 1, using a double negation in
|a C-style arithmetic context, in order to generate an array index for
|the color.
|
|I don't recall ever seeing it used in the way Steffen showed, though.
Because the devil is in your car!
That always makes a subdivision.
Other than that just dance this mess around.
--End of <YrT2m2dIlQQaEe+z@wooledge.org>
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)