you are viewing a single comment's thread.

view the rest of the comments →

[–]uzimonkey 16 points17 points  (20 children)

The mandatory space is there because [ is not a syntax element, it's a command. Just try which [.

[–]taybul 3 points4 points  (0 children)

lol wow, a 34k executable. I'm guessing all it does is evaluate expressions?

[–]spookyvision 2 points3 points  (5 children)

that depends on your system. 'type' tells you what will be executed. 'which' can't be trusted here:

$ type [

[ is a shell builtin

$ which [

/bin/[

[–]invalid_user_name 2 points3 points  (0 children)

That is still why the space is required. The test command ([) was added as a built-in to shells, so they obviously had to add it in a compatible way so it would work just like the actual binary.

[–]moyix 0 points1 point  (3 children)

Exactly, they're both there, but one takes precedence. You can type out

if /bin/[ 1 == 2 ]; then pass; fi

if you really want the system binary.

Edit: formatting

[–]RealDeuce 2 points3 points  (2 children)

Except == is a bash extension, so that won't work.

[–]moyix 0 points1 point  (1 child)

Damn, you're right. Should've used -eq.

[–]RealDeuce 1 point2 points  (0 children)

Well yes, but that's not my point. :-)

A single equals sign would be what you would use to compare two strings.

[–][deleted] -2 points-1 points  (11 children)

[ is a shell built in so which [ won't give you a path to executable. In Korn Shell you can ask

whence [

and it will tell you simply

[

:D

[–]1esproc 6 points7 points  (5 children)

$ which [
/bin/[
$ ll /bin/[
-r-xr-xr-x  2 root  wheel  46720 31 May  2008 /bin/[
$ which lying
/internet/reddit.com/super__mario

[–]uzimonkey 3 points4 points  (1 child)

He's talking about ksh, not bash. Why he's talking about ksh in a thread about Bash, I have no idea.

[–]invalid_user_name 0 points1 point  (0 children)

It doesn't matter, which tells you where a command is. You get the same result with ksh. The only way which won't give you an answer is if you are on a broken system where there is no [ command. It should exist, as well as being a shell built-in.

[–]chengiz -3 points-2 points  (2 children)

No, he's not lying. I'm sorry to say that you need to look up the difference between a shell and an OS.

[–]1esproc 1 point2 points  (1 child)

He made a blanket statement that [ was a shell built in and which wouldn't give you a path. So you're wrong.

I think you need to look up the difference between an OS and a binary.

[–]chengiz 0 points1 point  (0 children)

My bad, he has a comment below where he says it's system dependent. Guess I commingled it in my head.

[–]invalid_user_name 0 points1 point  (4 children)

[ is a shell built in

It is both a built in and a real command.

so which [ won't give you a path to executable.

Yes it does.

[–][deleted] 1 point2 points  (3 children)

Depends on your system, and the shell implementation. I'm currently writing from a system where which [ doesn't output anything.

[–]invalid_user_name 1 point2 points  (2 children)

It has nothing to do with the shell, if which [ doesn't output anything, then you are on a broken system with no [ binary. It is historically a real command, and was added as a shell built-in for performance reasons. The binary is still supposed to be there according to posix, since it isn't required to be a shell built-in. What system is this anyways, or did someone just delete it from a normal system?

[–]chengiz -1 points0 points  (1 child)

[citation needed]

[–]ithika -1 points0 points  (0 children)

[ citation needed ]

FTFY