5 ms·
This is pretty awesome, but I don't know if people often phrase their queries like that, and I'm not sure whether it's worth it to start phrasing it like this.
by Nyubis 12y ago
This is pretty awesome, but I don't know if people often phrase their queries like that, and I'm not sure whether it's worth it to start phrasing it like this. It doesn't seem to support more complex bash queries, so I'm not really sure how often this will be used.
- mattdanger 12y ago[ is part of Bash syntax
- frou_dh 12y ago...and perhaps surprisingly also a program sitting on disk. $ type [ [ is a shell builtin $ [ 1 -gt 0 bash: [: missing `]' $ whereis [ /bin/[ $ /bin/[ 1 -gt 0 # success
- mappu 12y agoYou got a root shell out of `/bin/[` ? Impressive :)
- e12e 12y agoHm, which version of [ is that? I get: $ /usr/bin/[ 1 -gt 0 && echo success /usr/bin/[: missing `]' $ /usr/bin/[ 1 -gt 0 ] && echo success success (This is from coreutils 8.13-3.5 on Debian GNU/Linux)
- frou_dh 12y agoWhat ships in OS X 10.9, presumably BSD-derived.
- embolalia 12y agoNooo! Mistake #0 about shell scripting is thinking [ is syntax. It makes it way more weird and inexplicable. [ is a command, just like any other. That's why there needs to be a space between it and the next thing, and why you have to use weird looking flags and such. This is why I prefer the command `test`. It does the same thing as `[`, but is more obviously a command. And when you see it as a command, it's obvious that any command can be used in an if directly; if is just checking the exit code. (Whenever I see someone doing `if [ $? -ne 0 ]`, it makes me cry.)
- manicdee 12y agotest is [
- jsmeaton 12y agoI'll bite. What should we be using instead of `if [ $? -ne 0 ]`? Because that's pretty standard in my (admittedly very basic) bash.
- schoen 12y agoInstead of somecommand if [ $? -ne 0 ]; then echo "it failed"; fi the parent commenter presumably wants to see if ! somecommand; then echo "it failed"; fi
- viraptor 12y agoOr: somecommand || echo "it failed" if it's just one statement. There are some cases where it just looks more natural. For example: start_service || log "already started"
- deleted 12y ago[deleted]
- JetSpiegel 12y ago> when you see it as a command, it's obvious that any command can be used in an if directly; if is just checking the exit code One of the best days of my life
- deleted 12y ago[deleted]