Sponsored Content
Top Forums Shell Programming and Scripting unable to access a variable not local to a while loop Post 302271148 by geekosaur on Wednesday 24th of December 2008 02:02:37 AM
Old 12-24-2008
You should be able to read any variable that has been set at that point. Assigning to it won't work because the pipe forces the while loop to run in a subshell; assignments will be visible within the while loop but will be lost when the loop is exited. I generally use temporary files to work around this, but sometimes run it in a "eval $(expression)" and have it echo the variable assignment(s) to stdout. (The latter avoids the various issues with temporary files but is rather more confusing to most people.)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to access variable outside loop

I am unable to access the value set inside the loop from outside loop . Thought of taking this to forum , I had seen other replies also , where a pipe takes the execution to another shell and mentioned thats the reason we do not get the variable outside loop . But I am getting an issue and I am... (1 Reply)
Discussion started by: Armaan_S
1 Replies

2. Shell Programming and Scripting

Not access variable outside loop when a reading a file

I am writing a shell script using the korn shell. It seems that I am only able to use local variables within a while loop that is reading a file. (I can't access a variable outside a previously used while loop.) It's been a while since I wrote shell scripts. Here is a sample cat file.txt... (4 Replies)
Discussion started by: ricardo.ludwig
4 Replies

3. Red Hat

Restrict local users to access ftp

Hi, I had installed vsftp in rhel5 and i want to restrict all the local users from accessing the ftp. i want to allow specific users to access the ftp server. Request you to please help. Thanks & regards Arun (1 Reply)
Discussion started by: Arun.Kakarla
1 Replies

4. Red Hat

Understanding local access to NFS export

Hello, I've inherited an NFS setup that allows external servers to write to an NFS share on a Centos box. Here is an example line from /etc/exports (there are four entries that only are different based on server IP adress). /exports/foobar... (4 Replies)
Discussion started by: KickstartUF
4 Replies

5. Ubuntu

Local Networking no longer possible-Unable to mount location

Unable to mount location Can anyone help with this please? Since recently installing 12.04 from a downloaded live CD onto my desktop computer, I have been unable to re-establish a network connection with my other... (2 Replies)
Discussion started by: Royalist
2 Replies

6. Homework & Coursework Questions

Remote Access vs Local Access

Dear Friends, This is not a problem , it's a course work (UNIX scenario).... As part of it I am searching Remote Attacks and find points as 1. Exploiting a listening service 2. Routing through Unix system that is providing security between 2 or more networks 3. User initiated Remote execution... (1 Reply)
Discussion started by: anespa
1 Replies

7. Red Hat

NFS share full access for local user

Hi All, Is it possible to give full access for a normal user in a NFS share? If its not possible is there a trick with which I can make it work? Thanks in advance Shyam (1 Reply)
Discussion started by: shyam2j
1 Replies

8. Shell Programming and Scripting

Unable to set Global variable outside while loop

Below is my code: count=0 if ... ... else ... find * -prune -type d | sort -r -n | while read d; do count=1 if ; then echo "Count1:$count" ... ... break 2; fi ... done ... fi echo "Count2:$count" (9 Replies)
Discussion started by: mohtashims
9 Replies

9. Shell Programming and Scripting

Unable to compare to a previous value of a variable in a while loop for a file

Hello All, I'm working on a script that will actually read a file consisting of data like the below:(ReportID,Sub_reportID,Sub_reportName) 1,1,ABC 1,2,DEF 1,3,GHI 2,1,JKL 2,2,MNO 3,1,PQR I want to read the Sub Report details for a Report_ID using while loop and write these values into... (6 Replies)
Discussion started by: venkat_reddy
6 Replies

10. Solaris

Solaris local access restriction other than sshd_config?

Hi All, As part of LDAP implementation we need to restrict users/groups locally on solaris machine: Options tried: sshd_config: as far as my testing it is restricting either user or group, as per the first preference. pam_access.so by default I am unable to find(need some help if this is... (0 Replies)
Discussion started by: Sridaran
0 Replies
break(1)							   User Commands							  break(1)

NAME
break, continue - shell built-in functions to escape from or advance within a controlling while, for, foreach, or until loop SYNOPSIS
sh break [n] continue [n] csh break continue ksh *break [n] *continue [n] ksh93 +break [n] +continue [n] DESCRIPTION
sh The break utility exits from the enclosing for or while loop, if any. If n is specified, break n levels. The continue utility resumes the next iteration of the enclosing for or while loop. If n is specified, resume at the n-th enclosing loop. csh The break utility resumes execution after the end of the nearest enclosing foreach or while loop. The remaining commands on the current line are executed. This allows multilevel breaks to be written as a list of break commands, all on one line. The continue utility continues execution of the next iteration of the nearest enclosing while or foreach loop. ksh The break utility exits from the enclosed for, while, until, or select loop, if any. If n is specified, then break n levels. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be exited. The continue utility resumes the next iteration of the enclosed for, while, until, or select loop. If n is specified then resume at the n- th enclosed loop. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be used. On this manual page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words that follow a command preceded by ** that are in the format of a variable assignment are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign, and also that word splitting and file name generation are not performed. ksh93 break is a shell special built-in that exits the smallest enclosing for, select, while, or until loop. It also exits the nth enclosing loop if n is specified. Execution continues at the command following the loop or loops. If n is specified, it must be a positive integer >=1. If n is larger than the number of enclosing loops, the last enclosing loop is exited. continue is a shell special built-in that continues execution at the top of the smallest enclosing for, select, while, or until loop, if any; or of the top of the nth enclosing loop if n is specified. If n is specified, it must be a positive integer >=1. If n is larger than the number of enclosing loops, the last enclosing loop is used. On this manual page, ksh93(1) commands that are preceded by one or two + symbols are special built-in commands and are treated the follow- ing ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Built-in commands are not valid function names. 5. Words following a command preceded by ++ that are in the format of a variable assignment are expanded with rules as a variable assignment. This means that tilde substitution is performed after the = sign and field splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), exit(1), ksh(1), ksh93(1), sh(1), attributes(5) SunOS 5.11 8 Apr 2008 break(1)
All times are GMT -4. The time now is 06:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy