Sponsored Content
Top Forums Shell Programming and Scripting What does xx mean in this while loop syntax? Post 302939284 by vgersh99 on Tuesday 24th of March 2015 10:36:00 AM
Old 03-24-2015
man ksh, yields:
Code:
       read [ -ACprsv ] [ -d delim] [ -n n] [ [ -N n] [ [ -t timeout] [ -u unit] [ vname?prompt ] [ vname ... ]
              The shell input mechanism.  One line is read and is broken up into fields using the characters in IFS as separators.  The escape charac-
              ter,  \,  is used to remove any special meaning for the next character and for line continuation.  The -d option causes the read to con-
              tinue to the first character of delim rather than new-line.  The -n option causes at most n bytes to read rather a full  line  but  will
              return  when  reading  from a slow device as soon as any characters have been read.  The -N option causes exactly n to be read unless an
              end-of-file has been encountered or the read times out because of the -t option.  In raw mode, -r, the \ character is not  treated  spe-
              cially.   The  first  field is assigned to the first vname, the second field to the second vname, etc., with leftover fields assigned to
              the last vname.  When vname has the binary attribute and -n or -N is specified, the bytes that are read are  stored  directly  into  the
              variable.   If  the  -v  is  specified,  then  the value of the first vname will be used as a default value when reading from a terminal
              device.  The -A option causes the variable vname to be unset and each field that is read to be stored  in  successive  elements  of  the
              indexed  array  vname.   The -C option causes the variable vname to be read as a compound variable.  Blanks will be ignored when finding
              the beginning open parenthesis.  The -p option causes the input line to be taken from the input pipe of a process spawned by  the  shell
              using  â&.  If the -s option is present, the input will be saved as a command in the history file.  The option -u can be used to specify
              a one digit file descriptor unit unit to read from.  The file descriptor can be opened with the  exec  special  built-in  command.   The
              default  value of unit n is 0.  The option -t is used to specify a timeout in seconds when reading from a terminal or pipe.  If vname is
              omitted, then REPLY is used as the default vname.  An end-of-file with the -p option causes cleanup for this process so that another can
              be  spawned.   If  the  first  argument contains a ?, the remainder of this word is used as a prompt on standard error when the shell is
              interactive.  The exit status is 0 unless an end-of-file is encountered or read has timed out.

This User Gave Thanks to vgersh99 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

for loop syntax trouble

i don't get what's wrong here. i'm writing a shell script that takes 1 argument (a number) from the command-line, but it's throwing an error: Syntax error: Bad for loop variable doesn't make much sense for (( i = 1; i = ${1}; i++ )) # error points to this line everytime do echo... (9 Replies)
Discussion started by: visitorQ
9 Replies

2. Shell Programming and Scripting

syntax error in while loop

Hi, I have the following script (compile_mercury) and I get this error: I have no idea why...and I have written this script completely in linux (bash) and not in windows. **************** ./compile_mercury: line 136: syntax error near unexpected token `done' ./compile_mercury: line 136:... (1 Reply)
Discussion started by: habzone2007
1 Replies

3. Shell Programming and Scripting

Problems with syntax in a loop (AWK)

Hi guys, I'm trying to loop through a number of files that is set by whatever is in a field. eg. The idea is to split FILELIST down into fields, it could contain 1 - 999 fields and it's bar delimited. I thought simple, count the number of fields in the field and then loop... (1 Reply)
Discussion started by: Peejay
1 Replies

4. Shell Programming and Scripting

While Loop Syntax help needed

Hi everyone, Can ny1 help me out regarding while loop arguments i.e. what does -gt -ge -lt -le means? actually i am new to while loops (2 Replies)
Discussion started by: jojo123
2 Replies

5. Shell Programming and Scripting

for loop syntax

hi, I have to use for loop in my script. The below code is providing an output, 1,2,3,4,5..n. But i need to display the values one by one eg: it has to display the first value then exit from the loop and display the second value then exit till n(last value). for i in 1,2,3,4,5..n do ... (2 Replies)
Discussion started by: sreelu
2 Replies

6. UNIX for Dummies Questions & Answers

for-loop syntax

%%%%% (3 Replies)
Discussion started by: lucasvs
3 Replies

7. Shell Programming and Scripting

IF loop syntax error

I am trying to run a menu option though IF loops. I keep getting errors not allowed the menu to be processed correctly. Currently it will accept the first 2 statements but then crash on the 3rd. The 2nd and 3rd have the same syntax, so I do not understand why it breaks. #!/bin/bash while... (4 Replies)
Discussion started by: Ironguru
4 Replies

8. UNIX for Dummies Questions & Answers

[Solved] Syntax error for awk in a loop

can some one please tell me what is the problem with my syntax:confused: I have 100 files in one folder 1. want to read each of the line by line 2. calculate their number of the words between the first word and the last word of each line 3. create file for each file with number of words... (8 Replies)
Discussion started by: A-V
8 Replies

9. UNIX for Dummies Questions & Answers

Syntax error in for loop

I am using simple for loop, but getting syntax error when I run the code code #!/bin/ksh pls enter number read n for(i=1; i<=n; i++) do echo $i done syntax error + pls enter number + read n (5 Replies)
Discussion started by: stew
5 Replies

10. Shell Programming and Scripting

Use positional parameters in loop / while syntax in whiptail

I like to “optimize” / make more like a real program my bash script by replacing repetitious code which utilizes positional parameters. I am having two issues I cannot solve and would appreciate some assistance with resolving them. a) how to modify the whiptail checklist... (3 Replies)
Discussion started by: annacreek
3 Replies
READ(P) 						     POSIX Programmer's Manual							   READ(P)

NAME
read - read a line from standard input SYNOPSIS
read [-r] var... DESCRIPTION
The read utility shall read a single line from standard input. By default, unless the -r option is specified, backslash ( '' ) shall act as an escape character, as described in Escape Character (Back- slash) . If standard input is a terminal device and the invoking shell is interactive, read shall prompt for a continuation line when: * The shell reads an input line ending with a backslash, unless the -r option is specified. * A here-document is not terminated after a <newline> is entered. The line shall be split into fields as in the shell (see Field Splitting ); the first field shall be assigned to the first variable var, the second field to the second variable var, and so on. If there are fewer var operands specified than there are fields, the leftover fields and their intervening separators shall be assigned to the last var. If there are fewer fields than vars, the remaining vars shall be set to empty strings. The setting of variables specified by the var operands shall affect the current shell execution environment; see Shell Execution Environ- ment . If it is called in a subshell or separate utility execution environment, such as one of the following: (read foo) nohup read ... find . -exec read ... ; it shall not affect the shell variables in the caller's environment. OPTIONS
The read utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines. The following option is supported: -r Do not treat a backslash character in any special way. Consider each backslash to be part of the input line. OPERANDS
The following operand shall be supported: var The name of an existing or nonexisting shell variable. STDIN
The standard input shall be a text file. INPUT FILES
None. ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of read: IFS Determine the internal field separators used to delimit fields; see Shell Variables . LANG Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of IEEE Std 1003.1-2001, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES . PS2 Provide the prompt string that an interactive shell shall write to standard error when a line ending with a backslash is read and the -r option was not specified, or if a here-document is not terminated after a <newline> is entered. ASYNCHRONOUS EVENTS
Default. STDOUT
Not used. STDERR
The standard error shall be used for diagnostic messages and prompts for continued input. OUTPUT FILES
None. EXTENDED DESCRIPTION
None. EXIT STATUS
The following exit values shall be returned: 0 Successful completion. >0 End-of-file was detected or an error occurred. CONSEQUENCES OF ERRORS
Default. The following sections are informative. APPLICATION USAGE
The -r option is included to enable read to subsume the purpose of the line utility, which is not included in IEEE Std 1003.1-2001. The results are undefined if an end-of-file is detected following a backslash at the end of a line when -r is not specified. EXAMPLES
The following command: while read -r xx yy do printf "%s %s " "$yy" "$xx" done < input_file prints a file with the first field of each line moved to the end of the line. RATIONALE
The read utility historically has been a shell built-in. It was separated off into its own utility to take advantage of the richer descrip- tion of functionality introduced by this volume of IEEE Std 1003.1-2001. Since read affects the current shell execution environment, it is generally provided as a shell regular built-in. If it is called in a sub- shell or separate utility execution environment, such as one of the following: (read foo) nohup read ... find . -exec read ... ; it does not affect the shell variables in the environment of the caller. FUTURE DIRECTIONS
None. SEE ALSO
Shell Command Language COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 READ(P)
All times are GMT -4. The time now is 01:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy