Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

While reading up on how to set up grub, one article mentioned that I need to use a syntax like

echo \(hd0,0\) >> /boot/grub/grub.conf

or

echo '(hd0,0)' >> /boot/grub/grub.conf

because at the command line parenthesis have a special way of being interpreted. What is special about the parenthesis? How are they interpreted?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

Parentheses denote a subshell in bash. To quote the man page:

(list)    list  is  executed  in  a  subshell  environment (see COMMAND
          EXECUTION ENVIRONMENT below).  Variable assignments and builtin 
          commands that affect the shell's environment do not remain in 
          effect after the command completes.  The return status is the
          exit status of list.

where a list is just a normal sequence of commands.

This is actually quite portable and not specific to just bash though. The POSIX Shell Command Language spec has the following description for the (compound-list) syntax:

Execute compound-list in a subshell environment; see Shell Execution Environment. Variable assignments and built-in commands that affect the environment shall not remain in effect after the list finishes.

share|improve this answer
    
In bash and other shells...? –  jasonwryan Dec 5 '11 at 0:20
2  
bash is the one i was asking about... –  Steve Brown Dec 5 '11 at 0:24
add comment

A command list embedded between parentheses runs as a subshell.

Variables in a subshell are not visible outside the block of code in the subshell. They are not accessible to the parent process, to the shell that launched the subshell. These are, in effect, local variables.

See Linuxtopia - Chapter 20. Subshells

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.