Re: Newbie-ish question about ( [ and [[



Michael wrote:
Thanx for the great input. I think I'm beginning to get the light bulb
turned on.

Here's what I believe y'all said.

The construct ( blah ) means:

( # Open a new subshell
Blah # Execute the "Blah" command(s) and save the exit status
) # Close the subshell and return the exit status of Blah to
the calling shell

There's nothing like "closing" a subshell.

( ... ) will invoke a subshell that executes the commands '...'.



So, I can actually put any command or command string inside of the "(
)" that returns an exit status that the "if" then evaluates. Operators
are permitted, but only as they relate to the commands.

You don't need a subshell if you want an if-construct to check for the
return status; just use the commands as they are, for example...

if grep pattern <file.txt
then
: ...
fi

A subshell is helpful if you want your environment unchanged but the
commands want their own environment, e.g. as in

( cd /some/dir ; tar cf - ) | ( cd /another/dir ; tar xf - )

Here in both subshells the working directories are changed as needed.


Next, the construct [ foo ] means:

[ # Execute the alias of the test command on the following
Blah # something that the test command can legally evaluate
] # terminus of what is being tested

Not necessarily an alias. There might be a program /bin/[ or it might
also be a shell built-in, or both.

$ ls -l /usr/bin/[
lrwxrwxrwx 1 root root 4 2003-06-05 01:14 /usr/bin/[ -> test

$ type [
[ is a shell builtin


Janis


So the contents of the "[ ]" must contain operators, not commands;
unless an operator is operating on the result of a command.

Did I get it right?

Thanx!

.



Relevant Pages

  • Re: administrative password, resetting?
    ... mkdir temphack *creates the folder temphack ... Now what you have just done is told the computer to backup the command ... If the Administrator Account is called Frank and you want the password ... "net user Frank blah" ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: administrative password, resetting?
    ... mkdir temphack *creates the folder temphack ... Now what you have just done is told the computer to backup the command ... If the Administrator Account is called Frank and you want the password ... "net user Frank blah" ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: administrative password, resetting?
    ... mkdir temphack *creates the folder temphack ... Now what you have just done is told the computer to backup the command ... If the Administrator Account is called Frank and you want the password ... "net user Frank blah" ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Newbie-ish question about ( [ and [[
    ... The construct (blah) means: ... Blah # Execute the "Blah" commandand save the exit status ... I can actually put any command or command string inside of the "( ... Blah # something that the test command can legally evaluate ...
    (comp.unix.shell)
  • setting an alias in .cshrc with parentheses in it ...
    ... I often run this command: ... includes parentheses. ... So, to save time, I added this line to my .cshrc: ... MSIE blah blah)" ...
    (freebsd-questions)