<HTML><HEAD><TITLE>Built-In Commands - scan manual page</TITLE></HEAD><BODY> <DL> <DD><A HREF="scan.htm#M2" NAME="L789">NAME</A> <DL><DD>scan - Parse string using conversion specifiers in the style of sscanf</DL> <DD><A HREF="scan.htm#M3" NAME="L790">SYNOPSIS</A> <DL> <DD><B>scan </B><I>string format varName </I>?<I>varName ...</I>? </DL> <DD><A HREF="scan.htm#M4" NAME="L791">INTRODUCTION</A> <DD><A HREF="scan.htm#M5" NAME="L792">DETAILS ON SCANNING</A> <DL> <DD><A HREF="scan.htm#M6" NAME="L793"><B>d</B></A> <DD><A HREF="scan.htm#M7" NAME="L794"><B>o</B></A> <DD><A HREF="scan.htm#M8" NAME="L795"><B>x</B></A> <DD><A HREF="scan.htm#M9" NAME="L796"><B>c</B></A> <DD><A HREF="scan.htm#M10" NAME="L797"><B>s</B></A> <DD><A HREF="scan.htm#M11" NAME="L798"><B>e</B> or <B>f</B> or <B>g</B></A> <DD><A HREF="scan.htm#M12" NAME="L799"><B>[</B><I>chars</I><B>]</B></A> <DD><A HREF="scan.htm#M13" NAME="L800"><B>[^</B><I>chars</I><B>]</B></A> </DL> <DD><A HREF="scan.htm#M14" NAME="L801">DIFFERENCES FROM ANSI SSCANF</A> <DL> </DL> <DD><A HREF="scan.htm#M15" NAME="L802">KEYWORDS</A> </DL><HR> <H3><A NAME="M2">NAME</A></H3> scan - Parse string using conversion specifiers in the style of sscanf <H3><A NAME="M3">SYNOPSIS</A></H3> <B>scan </B><I>string format varName </I>?<I>varName ...</I>?<BR> <H3><A NAME="M4">INTRODUCTION</A></H3> This command parses fields from an input string in the same fashion as the ANSI C <B>sscanf</B> procedure and returns a count of the number of conversions performed, or -1 if the end of the input string is reached before any conversions have been performed. <I>String</I> gives the input to be parsed and <I>format</I> indicates how to parse it, using <B>%</B> conversion specifiers as in <B>sscanf</B>. Each <I>varName</I> gives the name of a variable; when a field is scanned from <I>string</I> the result is converted back into a string and assigned to the corresponding variable. <H3><A NAME="M5">DETAILS ON SCANNING</A></H3> <B>Scan</B> operates by scanning <I>string</I> and <I>formatString</I> together. If the next character in <I>formatString</I> is a blank or tab then it matches any number of white space characters in <I>string</I> (including zero). Otherwise, if it isn't a <B>%</B> character then it must match the next character of <I>string</I>. When a <B>%</B> is encountered in <I>formatString</I>, it indicates the start of a conversion specifier. A conversion specifier contains three fields after the <B>%</B>: a <B>*</B>, which indicates that the converted value is to be discarded instead of assigned to a variable; a number indicating a maximum field width; and a conversion character. All of these fields are optional except for the conversion character. <P> When <B>scan</B> finds a conversion specifier in <I>formatString</I>, it first skips any white-space characters in <I>string</I>. Then it converts the next input characters according to the conversion specifier and stores the result in the variable given by the next argument to <B>scan</B>. The following conversion characters are supported: <P> <DL> <P><DT><A NAME="M6"><B>d</B></A><DD> The input field must be a decimal integer. It is read in and the value is stored in the variable as a decimal string. <P><DT><A NAME="M7"><B>o</B></A><DD> The input field must be an octal integer. It is read in and the value is stored in the variable as a decimal string. <P><DT><A NAME="M8"><B>x</B></A><DD> The input field must be a hexadecimal integer. It is read in and the value is stored in the variable as a decimal string. <P><DT><A NAME="M9"><B>c</B></A><DD> A single character is read in and its binary value is stored in the variable as a decimal string. Initial white space is not skipped in this case, so the input field may be a white-space character. This conversion is different from the ANSI standard in that the input field always consists of a single character and no field width may be specified. <P><DT><A NAME="M10"><B>s</B></A><DD> The input field consists of all the characters up to the next white-space character; the characters are copied to the variable. <P><DT><A NAME="M11"><B>e</B> or <B>f</B> or <B>g</B></A><DD> The input field must be a floating-point number consisting of an optional sign, a string of decimal digits possibly containing a decimal point, and an optional exponent consisting of an <B>e</B> or <B>E</B> followed by an optional sign and a string of decimal digits. It is read in and stored in the variable as a floating-point string. <P><DT><A NAME="M12"><B>[</B><I>chars</I><B>]</B></A><DD> The input field consists of any number of characters in <I>chars</I>. The matching string is stored in the variable. If the first character between the brackets is a <B>]</B> then it is treated as part of <I>chars</I> rather than the closing bracket for the set. <P><DT><A NAME="M13"><B>[^</B><I>chars</I><B>]</B></A><DD> The input field consists of any number of characters not in <I>chars</I>. The matching string is stored in the variable. If the character immediately following the <B>^</B> is a <B>]</B> then it is treated as part of the set rather than the closing bracket for the set. <P></DL> <P> The number of characters read from the input for a conversion is the largest number that makes sense for that particular conversion (e.g. as many decimal digits as possible for <B>%d</B>, as many octal digits as possible for <B>%o</B>, and so on). The input field for a given conversion terminates either when a white-space character is encountered or when the maximum field width has been reached, whichever comes first. If a <B>*</B> is present in the conversion specifier then no variable is assigned and the next scan argument is not consumed. <H3><A NAME="M14">DIFFERENCES FROM ANSI SSCANF</A></H3> The behavior of the <B>scan</B> command is the same as the behavior of the ANSI C <B>sscanf</B> procedure except for the following differences: <P> <DL> <P><DT>[1]<DD> <B>%p</B> and <B>%n</B> conversion specifiers are not currently supported. <P><DT>[2]<DD> For <B>%c</B> conversions a single character value is converted to a decimal string, which is then assigned to the corresponding <I>varName</I>; no field width may be specified for this conversion. <P><DT>[3]<DD> The <B>l</B>, <B>h</B>, and <B>L</B> modifiers are ignored; integer values are always converted as if there were no modifier present and real values are always converted as if the <B>l</B> modifier were present (i.e. type <B>double</B> is used for the internal representation). <P></DL> <H3><A NAME="M15">KEYWORDS</A></H3> <A href="../Keywords/C.htm#conversion specifier">conversion specifier</A>, <A href="../Keywords/P.htm#parse">parse</A>, <A href="../Keywords/S.htm#scan">scan</A> <HR><PRE> <A HREF="../copyright.htm">Copyright</A> © 1993 The Regents of the University of California. <A HREF="../copyright.htm">Copyright</A> © 1994-1996 Sun Microsystems, Inc. <A HREF="../copyright.htm">Copyright</A> © 1995-1997 Roger E. Critchlow Jr.</PRE> </BODY></HTML>