Sponsored Content
Top Forums Shell Programming and Scripting Ls help: ls not working with start character search (^) Post 302786499 by Don Cragun on Wednesday 27th of March 2013 03:00:11 PM
Old 03-27-2013
Quote:
Originally Posted by rveri
... ... ...

Don thanks for pointing out the difference of use when "shell uses filename pattern matching" & when "Regular expression uses pattern matching".
Is there a way we can figure out which is shell doing, and which is doing by regular expressions.


For example with the below example: How to figure out which portion is shell or regex performing the operation:

Code:
# ls -l bbcbbc
-rw-------   1 useradm    users            0 Mar 26 15:27 bbcbbc


# ls -l !([c-z])?[c][b][b][b-d]
-rw-------   1 useradm    users            0 Mar 26 15:27 bbcbbc


echo $SHELL
/usr/bin/ksh
#OS= hp-ux 11.23


Thanks..
In general, the answer is to read the man pages. But as a high altitude first cut, any unquoted argument passed to the shell that is not a parameter expansion (i.e., $name or ${...name...} that is not part of a shell command lanuage construct (e.g., if, then, else, fi, case, esac, ...) will be subject to pathname expansion.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Working out end time from start + elapsed

Hi, I'm writing a script and have become stuck trying to define a variable (COMP) by adding an elapsed time (ELAPSE e.g 00:55) to a start time (START e.g 23:50). Can anybody give me a solution as to how I can get a completion time in hh:mm from the variables above? thanks Richard (4 Replies)
Discussion started by: rik1551
4 Replies

2. Shell Programming and Scripting

read a string from its end to its start and stop when you find a specific character

How can I do this? Actually I have a file which contains a path e.g. /home/john/Music/hello.mp3 and I want to take only the filename (hello.mp3) So, I need to read the file from its end to its start till the character "/" Is this possible? Thanks, I am sure you'll not disappoint me here! Oh,... (9 Replies)
Discussion started by: hakermania
9 Replies

3. Solaris

Solaris 10, start inetd in a zone not working

Hello all, I`ve the following problem - I cannot start inetd in any way possible: bash-3.00# svcs inetd STATE STIME FMRI offline Jul_30 svc:/network/inetd:default bash-3.00# bash-3.00# svcadm enable -r inetd bash-3.00# svcs inetd STATE STIME FMRI... (6 Replies)
Discussion started by: click
6 Replies

4. Slackware

pppoe-start not working

Hello. I'm new here and i'm new to slack (concept) as well. I made a connection for pppoe with pppoe-setup, bringed up eth0 with ifconfig but when i try pppoe-connect i get "Cannot determine ethernet address for proxy ARP" and with pppoe-start i get "child pppd process terminated". How can i make... (0 Replies)
Discussion started by: editheraven
0 Replies

5. Shell Programming and Scripting

escape character not working

I need to change a pattern with single quotes # echo "serversignature: 'On'" serversignature: 'On' I did # echo "serversignature: 'On'" | sed 's/.*serversignature.*/serversignature: 'Off'/' serversignature: Off The output I need is with single quotes. But its swallowing it. ... (2 Replies)
Discussion started by: anilcliff
2 Replies

6. Shell Programming and Scripting

How to start working with GNU PLOT??

Dear Experts, I wanted to plot a graph with respect to values from a file. I'm doing it with Excel 2007, but I want to create the chart in script itself. I searched in internet for GNUPLOt. But I couldn't understand anything. Here is my situation. I have a file having values separated by "|".... (7 Replies)
Discussion started by: Naga06
7 Replies

7. Shell Programming and Scripting

how to specify start and stop of a search string

I am trying to extract a string from a line of text. Currently I am using grep -o 'startofstring(.........' The string is not always the same size. The string I'm trying to extract starts with 'test(' ends with ')'. ex "blah,blah,blah,test(stringoftext),blah blah" How do I... (4 Replies)
Discussion started by: jeepguy
4 Replies

8. UNIX for Dummies Questions & Answers

Appending a character(#) with string search at the start of the line

Hello, I have been browsing through the forum, but unable to find a solution for my requirement. I need to go through a file and search for /home/users and insert a # symbol at the start /home/users. Example output is #/home/users. Can you please help me with the awk or sed command for... (1 Reply)
Discussion started by: chandu123
1 Replies

9. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

10. Shell Programming and Scripting

How can I search with start and end criteria?

Hello I'm using cygwin and wouldlike extract information from an xml file according specific values, but don't know how. Let's say in a file content looks like this: <tab> SURNAME=Mustermann NAME=Max CUSTOMER SINCE= 18.01.2000 ADDRESS=Birmingham ... (2 Replies)
Discussion started by: witchblade
2 Replies
fnmatch(5)						Standards, Environments, and Macros						fnmatch(5)

NAME
fnmatch - file name pattern matching DESCRIPTION
The pattern matching notation described below is used to specify patterns for matching strings in the shell. Historically, pattern match- ing notation is related to, but slightly different from, the regular expression notation. For this reason, the description of the rules for this pattern matching notation is based on the description of regular expression notation described on the regex(5) manual page. Patterns Matching a Single Character The following patterns matching a single character match a single character: ordinary characters, special pattern characters and pattern bracket expressions. The pattern bracket expression will also match a single collating element. An ordinary character is a pattern that matches itself. It can be any character in the supported character set except for NUL, those spe- cial shell characters that require quoting, and the following three special pattern characters. Matching is based on the bit pattern used for encoding the character, not on the graphic representation of the character. If any character (ordinary, shell special, or pattern spe- cial) is quoted, that pattern will match the character itself. The shell special characters always require quoting. When unquoted and outside a bracket expression, the following three characters will have special meaning in the specification of patterns: ? A question-mark is a pattern that will match any character. * An asterisk is a pattern that will match multiple characters, as described in Patterns Matching Multiple Characters, below. [ The open bracket will introduce a pattern bracket expression. The description of basic regular expression bracket expressions on the regex(5) manual page also applies to the pattern bracket expression, except that the exclamation-mark character ( ! ) replaces the circumflex character (^) in its role in a non-matching list in the regular expression notation. A bracket expression starting with an unquoted circumflex character produces unspecified results. The restriction on a circumflex in a bracket expression is to allow implementations that support pattern matching using the circumflex as the negation character in addition to the exclamation-mark. A portable application must use something like [^!] to match either character. When pattern matching is used where shell quote removal is not performed (such as in the argument to the find -name primary when find is being called using one of the exec functions, or in the pattern argument to the fnmatch(3C) function, special characters can be escaped to remove their special meaning by preceding them with a backslash character. This escaping backslash will be discarded. The sequence \ rep- resents one literal backslash. All of the requirements and effects of quoting on ordinary, shell special and special pattern characters will apply to escaping in this context. Both quoting and escaping are described here because pattern matching must work in three separate circumstances: o Calling directly upon the shell, such as in pathname expansion or in a case statement. All of the following will match the string or file abc: abc "abc" a"b"c ac a[b]c a["b"]c a[]c a[""]c a?c a*c The following will not: "a?c" a*c a[b]c o Calling a utility or function without going through a shell, as described for find(1) and the function fnmatch(3C) o Calling utilities such as find, cpio, tar or pax through the shell command line. In this case, shell quote removal is performed before the utility sees the argument. For example, in: find /bin -name ec[h]o -print after quote removal, the backslashes are presented to find and it treats them as escape characters. Both precede ordinary characters, so the c and h represent themselves and echo would be found on many historical systems (that have it in /bin). To find a file name that con- tained shell special characters or pattern characters, both quoting and escaping are required, such as: pax -r ... "*a(?" to extract a filename ending with a(?. Conforming applications are required to quote or escape the shell special characters (sometimes called metacharacters). If used without this protection, syntax errors can result or implementation extensions can be triggered. For example, the KornShell supports a series of extensions based on parentheses in patterns; see ksh(1) Patterns Matching Multiple Characters The following rules are used to construct patterns matching multiple characters from patterns matching a single character: o The asterisk (*) is a pattern that will match any string, including the null string. o The concatenation of patterns matching a single character is a valid pattern that will match the concatenation of the single charac- ters or collating elements matched by each of the concatenated patterns. o The concatenation of one or more patterns matching a single character with one or more asterisks is a valid pattern. In such patterns, each asterisk will match a string of zero or more characters, matching the greatest possible number of characters that still allows the remainder of the pattern to match the string. Since each asterisk matches zero or more occurrences, the patterns a*b and a**b have identical functionality. Examples: a[bc] matches the strings ab and ac. a*d matches the strings ad, abd and abcd, but not the string abc. a*d* matches the strings ad, abcd, abcdef, aaaad and adddd. *a*d matches the strings ad, abcd, efabcd, aaaad and adddd. Patterns Used for Filename Expansion The rules described so far in Patterns Matching Multiple Characters and Patterns Matching a Single Character are qualified by the following rules that apply when pattern matching notation is used for filename expansion. 1. The slash character in a pathname must be explicitly matched by using one or more slashes in the pattern; it cannot be matched by the asterisk or question-mark special characters or by a bracket expression. Slashes in the pattern are identified before bracket expres- sions; thus, a slash cannot be included in a pattern bracket expression used for filename expansion. For example, the pattern a[b/c]d will not match such pathnames as abd or a/d. It will only match a pathname of literally a[b/c]d. 2. If a filename begins with a period (.), the period must be explicitly matched by using a period as the first character of the pattern or immediately following a slash character. The leading period will not be matched by: o the asterisk or question-mark special characters o a bracket expression containing a non-matching list, such as: [!a] a range expression, such as: [%-0] or a character class expression, such as: [[:punct:]] It is unspecified whether an explicit period in a bracket expression matching list, such as: [.abc] can match a leading period in a filename. 3. Specified patterns are matched against existing filenames and pathnames, as appropriate. Each component that contains a pattern char- acter requires read permission in the directory containing that component. Any component, except the last, that does not contain a pat- tern character requires search permission. For example, given the pattern: /foo/bar/x*/bam search permission is needed for directories / and foo, search and read permissions are needed for directory bar, and search permission is needed for each x* directory. If the pattern matches any existing filenames or pathnames, the pattern will be replaced with those filenames and pathnames, sorted according to the collating sequence in effect in the current locale. If the pattern contains an invalid bracket expression or does not match any existing filenames or pathnames, the pattern string is left unchanged. SEE ALSO
find(1), ksh(1), fnmatch(3C), regex(5) SunOS 5.10 28 Mar 1995 fnmatch(5)
All times are GMT -4. The time now is 05:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy