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.

I connect to server with PuTTY from Windows.

I have a long yet not touched (I suppose) by hands of local admin config:

$ cat /opt/jira/.subversion/config
...    
### must be enabled, which is typically done by setting the
### 'enable-auto-props' option.
# *.c = svn:eol-style=native
# *.cpp = svn:eol-style=native
...

Want to see if there are lines, which begin with something not #:

$ cat /opt/jira/.subversion/config | grep -P "$[^#]"
zsh: bad math expression: operand expected at `^#'
$
[1]    broken pipe  cat /opt/jira/.subversion/config

$ cat /opt/jira/.subversion/config | grep -P "\$[^#]"

$ cat /opt/jira/.subversion/config | grep -P "\$#"

$ cat /opt/jira/.subversion/config | grep -P "$#"
### details, see Debian Bug #413102):
# global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo

Can anyone explain why 2nd and 3rd outputs are same empty and what is that 4th?

UPD: here file is:

### This file configures various client-side behaviors.
###
### The commented-out examples below are intended to demonstrate
### how to use this file.

### Section for authentication and authorization customizations.
[auth]
### Set store-passwords to 'no' to avoid storing passwords in the
### auth/ area of your config directory.  It defaults to 'yes'.
### Note that this option only prevents saving of *new* passwords;
### it doesn't invalidate existing passwords.  (To do that, remove
### the cache files by hand as described in the Subversion book.)
# store-passwords = no
### Set store-auth-creds to 'no' to avoid storing any subversion
### credentials in the auth/ area of your config directory.
### It defaults to 'yes'.  Note that this option only prevents
### saving of *new* credentials;  it doesn't invalidate existing
### caches.  (To do that, remove the cache files by hand.)
# store-auth-creds = no

### Section for configuring external helper applications.
[helpers]
### Set editor to the command used to invoke your text editor.
###   This will override the environment variables that Subversion
###   examines by default to find this information ($EDITOR,
###   et al).
# editor-cmd = editor (vi, emacs, notepad, etc.)
### Set diff-cmd to the absolute path of your 'diff' program.
###   This will override the compile-time default, which is to use
###   Subversion's internal diff implementation.
# diff-cmd = diff_program (diff, gdiff, etc.)
### Set diff3-cmd to the absolute path of your 'diff3' program.
###   This will override the compile-time default, which is to use
###   Subversion's internal diff3 implementation.
# diff3-cmd = diff3_program (diff3, gdiff3, etc.)
### Set diff3-has-program-arg to 'true' or 'yes' if your 'diff3'
###   program accepts the '--diff-program' option.
# diff3-has-program-arg = [true | false]
### Set merge-tool-cmd to the command used to invoke your external
### merging tool of choice. Subversion will pass 4 arguments to
### the specified command: base theirs mine merged
# merge-tool-cmd = merge_command

### Section for configuring tunnel agents.
[tunnels]
### Configure svn protocol tunnel schemes here.  By default, only
### the 'ssh' scheme is defined.  You can define other schemes to
### be used with 'svn+scheme://hostname/path' URLs.  A scheme
### definition is simply a command, optionally prefixed by an
### environment variable name which can override the command if it
### is defined.  The command (or environment variable) may contain
### arguments, using standard shell quoting for arguments with
### spaces.  The command will be invoked as:
###   <command> <hostname> svnserve -t
### (If the URL includes a username, then the hostname will be
### passed to the tunnel agent as <user>@<hostname>.)  Here we
### redefine the built-in 'ssh' scheme to avoid an unfortunate
### interaction with the "ControlMaster auto" feature (for
### details, see Debian Bug #413102):
ssh = $SVN_SSH ssh -o ControlMaster=no
### If you wanted to define a new 'rsh' scheme, to be used with
### 'svn+rsh:' URLs, you could do so as follows:
# rsh = rsh
### Or, if you wanted to specify a full path and arguments:
# rsh = /path/to/rsh -l myusername
### On Windows, if you are specifying a full path to a command,
### use a forward slash (/) or a paired backslash (\\) as the
### path separator.  A single backslash will be treated as an
### escape for the following character.

### Section for configuring miscelleneous Subversion options.
[miscellany]
### Set global-ignores to a set of whitespace-delimited globs
### which Subversion will ignore in its 'status' output, and
### while importing or adding files and directories.
### '*' matches leading dots, e.g. '*.rej' matches '.foo.rej'.
# global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo
#   *.rej *~ #*# .#* .*.swp .DS_Store
### Set log-encoding to the default encoding for log messages
# log-encoding = latin1
### Set use-commit-times to make checkout/update/switch/revert
### put last-committed timestamps on every file touched.
# use-commit-times = yes
### Set no-unlock to prevent 'svn commit' from automatically
### releasing locks on files.
# no-unlock = yes
### Set mime-types-file to a MIME type registry file, used to
### provide hints to Subversion's MIME type auto-detection
### algorithm.
# mime-types-file = /path/to/mime.types
### Set preserved-conflict-file-exts to a whitespace-delimited
### list of patterns matching file extensions which should be
### preserved in generated conflict file names.  By default,
### conflict files use custom extensions.
# preserved-conflict-file-exts = doc ppt xls od?
### Set enable-auto-props to 'yes' to enable automatic properties
### for 'svn add' and 'svn import', it defaults to 'no'.
### Automatic properties are defined in the section 'auto-props'.
# enable-auto-props = yes
### Set interactive-conflicts to 'no' to disable interactive
### conflict resolution prompting.  It defaults to 'yes'.
# interactive-conflicts = no

### Section for configuring automatic properties.
[auto-props]
### The format of the entries is:
###   file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?').  All entries which match (case-insensitively) will be
### applied to the file.  Note that auto-props functionality
### must be enabled, which is typically done by setting the
### 'enable-auto-props' option.
# *.c = svn:eol-style=native
# *.cpp = svn:eol-style=native
# *.h = svn:eol-style=native
# *.dsp = svn:eol-style=CRLF
# *.dsw = svn:eol-style=CRLF
# *.sh = svn:eol-style=native;svn:executable
# *.txt = svn:eol-style=native
# *.png = svn:mime-type=image/png
# *.jpg = svn:mime-type=image/jpeg
# Makefile = svn:eol-style=native
share|improve this question
    
$ is "end of line", why are you putting that in front of your pattern? –  Mat May 12 '12 at 7:11
    
@Mat, my mistake. –  Nakilon May 12 '12 at 11:05

2 Answers 2

up vote 4 down vote accepted

Inside double quotes, the characters $"\` remain special. You may be confusing them with single quotes: inside single quotes, all characters are interpreted literally, except for ' itself which ends the string literal.

$ cat /opt/jira/.subversion/config | grep -P "$[^#]"
zsh: bad math expression: operand expected at `^#'

$[…] is a deprecated syntax for arithmetic expressions, which can be written $((…)) like in POSIX shells. ^# is not a valid arithmetic expression; the shell expected an operand, such as a number or a variable name.

[1]    broken pipe  cat /opt/jira/.subversion/config

Since the second command in the pipeline aborted before consuming all the output from cat (it hadn't even started reading), the first command (cat) received a SIGPIPE.

$ cat /opt/jira/.subversion/config | grep -P "\$[^#]"
$ cat /opt/jira/.subversion/config | grep -P "\$#"

The backslash tells the shell to interpret the next character literally, so grep saw the pattern $[^#] or $#. These patterns mean “the end of the line followed by any character except #” and “the end of the line followed by #” respectively. Neither of these patterns can match anything.

$ cat /opt/jira/.subversion/config | grep -P "$#"

$# is the number of positional arguments ($1, $2, …, collectively accessible as $@), i.e. the arguments passed on the shell command line, or the arguments to a function if inside a function. In an interactive shell, there are usually no positional arguments, so grep saw the pattern 0.

The pattern you're looking for is ^[^#] (^ matches at the beginning of a line). Unless you mean to include the value of a shell variable or the output of a command in the pattern, use single quotes (it doesn't matter here, but it matters for some patterns, especially the ones that contain a backslash or a $). You don't need -P as this pattern is written in the same way in basic regexps (plain grep), extended regexps (grep -E) and perl regexps (grep -P).

$ </opt/jira/.subversion/config grep '^[^#]'
share|improve this answer

I can't tell you exactly what happens to give the output you got in each case. However, there are two problems with what you're doing:

  1. The -P flag (for Perl-compatible regular expressions) is considered experimental, and isn't needed for what you're trying to do.

  2. $ is the end-of-line character in a regex. You should use the start-of-line character, ^.


cat /opt/jira/.subversion/config | grep "^[^#]"

or more concisely,

grep "^[^#]" /opt/jira/.subverison/config

should do what you want.

share|improve this answer
    
That's it! Don't know why I used $. But still interesting about outputs. –  Nakilon May 12 '12 at 11:02

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.