Sponsored Content
Top Forums Shell Programming and Scripting Does a variable lose its value outside the loop in shell script? Post 302829181 by Little on Thursday 4th of July 2013 06:35:02 AM
Old 07-04-2013
Quote:
Originally Posted by vidyadhar85
Pleas read my reply to your thread.. since you are piping the out put to while it will open a subshell and variable value would be lost once its back to main shell

use
while read line ; do
blah blah
blah
done < filename
i read your thread before also and i got the problem what you said. i just wanted a solution for that. so this code will do the same task what i want. thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing a variable to awk while in a shell for loop

I am a newbie to awk and c programming, however am not a unix newbie. However, I do need help with a kshell script I am writing. It is almost complete, the last step is killing me. Any help would be greatly appreciated. What I am trying to do is cat a text file that has usernames. Then, using... (2 Replies)
Discussion started by: synergy_texas
2 Replies

2. Shell Programming and Scripting

Shell script / Grep / Awk to variable and Loop

Hi, I have a text file with data in that I wish to extract, assign to a variable and process through a loop. Kind of the process that I am after: 1: Grep the text file for the values. Currently using: cat /root/test.txt | grep TESTING= | awk -F"=" '{ a = $2 } {print a}' | sort -u ... (0 Replies)
Discussion started by: Spoonless
0 Replies

3. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

4. Shell Programming and Scripting

Bourne Shell - Problem with while loop variable scope.

Hello I am having issues with a script I'm working on developing on a Solaris machine. The script is intended to find out how many times a particular user (by given userid) has logged into the local system for more than one hour today. Here is my while loop: last $user | grep -v 'sshd'... (7 Replies)
Discussion started by: DaveRich
7 Replies

5. Shell Programming and Scripting

Setting a variable in a while loop (.ksh script)

Hello Everyone, I'm still trying to grasp many concepts in .ksh scripting, one of them being variables inside loops. My problem is the following: * I'm trying to set a variable inside a while read loop to reuse it outside of said loop. My lines are the following :... (13 Replies)
Discussion started by: jimmy75_13
13 Replies

6. Shell Programming and Scripting

Shell Script Problems, Lose formatting when copy pasting from formatted file.

Hello, I'm having trouble with formatting some text via the terminal. I can get it perfectly formatted, but when I try and copy paste the text from the output file it loses it's formatting. Very frustrating! Basically I have 7 files (data data2 data3 data4 data5 data6 data7) containing a... (13 Replies)
Discussion started by: facetoe
13 Replies

7. Shell Programming and Scripting

[SHELL: /bin/sh] For loop using variable variable names

Simple enough problem I think, I just can't seem to get it right. The below doesn't work as intended, it's just a function defined in a much larger script: CheckValues() { for field in \ Group_ID \ Group_Title \ Rule_ID \ Rule_Severity \ ... (2 Replies)
Discussion started by: Vryali
2 Replies

8. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

9. Shell Programming and Scripting

Shell script use two variable in for loop

I want to create a shell script to add a user and modify its comment field mentioned in a file. 1. File value:- username comment field value xyz123 xyztesting abc123 abctesting def123 deftesting 2. i am using below loop to create user... (2 Replies)
Discussion started by: Anil
2 Replies

10. UNIX for Beginners Questions & Answers

How to write a Boolean variable which succeed and failed inside the if loop in shell script ?

I have if loop with multiple variable value check in if loop. How can i print only if loop satisfied variable and its value in shell script ? I dont want to check each variable in if loop. That makes my script larger. if ] then echo "Only satisfied variable with value" ... (3 Replies)
Discussion started by: prince1987
3 Replies
explain_readlink(3)					     Library Functions Manual					       explain_readlink(3)

NAME
explain_readlink - explain readlink(2) errors SYNOPSIS
#include <libexplain/readlink.h> const char *explain_readlink(const char *pathname, char *data, size_t data_size); const char *explain_errno_readlink(int errnum, const char *pathname, char *data, size_t data_size); void explain_message_readlink(char *message, int message_size, const char *pathname, char *data, size_t data_size); void explain_message_errno_readlink(char *message, int message_size, int errnum, const char *pathname, char *data, size_t data_size); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the readlink(2) system call. explain_readlink const char *explain_readlink(const char *pathname, char *data, size_t data_size); The explain_readlink function is used to obtain an explanation of an error returned by the readlink(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (readlink(pathname, data, data_size) < 0) { fprintf(stderr, "%s ", explain_readlink(pathname, data, data_size)); exit(EXIT_FAILURE); } pathname The original pathname, exactly as passed to the readlink(2) system call. data The original data, exactly as passed to the readlink(2) system call. data_size The original data_size, exactly as passed to the readlink(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_errno_readlink const char *explain_errno_readlink(int errnum, const char *pathname, char *data, size_t data_size); The explain_errno_readlink function is used to obtain an explanation of an error returned by the readlink(2) system call. The least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (readlink(pathname, data, data_size) < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_readlink(err, pathname, data, data_size)); exit(EXIT_FAILURE); } errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. pathname The original pathname, exactly as passed to the readlink(2) system call. data The original data, exactly as passed to the readlink(2) system call. data_size The original data_size, exactly as passed to the readlink(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_message_readlink void explain_message_readlink(char *message, int message_size, const char *pathname, char *data, size_t data_size); The explain_message_readlink function may be used to obtain an explanation of an error returned by the readlink(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (readlink(pathname, data, data_size) < 0) { char message[3000]; explain_message_readlink(message, sizeof(message), pathname, data, data_size); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. pathname The original pathname, exactly as passed to the readlink(2) system call. data The original data, exactly as passed to the readlink(2) system call. data_size The original data_size, exactly as passed to the readlink(2) system call. explain_message_errno_readlink void explain_message_errno_readlink(char *message, int message_size, int errnum, const char *pathname, char *data, size_t data_size); The explain_message_errno_readlink function may be used to obtain an explanation of an error returned by the readlink(2) system call. The least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (readlink(pathname, data, data_size) < 0) { int err = errno; char message[3000]; explain_message_errno_readlink(message, sizeof(message), err, pathname, data, data_size); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. pathname The original pathname, exactly as passed to the readlink(2) system call. data The original data, exactly as passed to the readlink(2) system call. data_size The original data_size, exactly as passed to the readlink(2) system call. SEE ALSO
readlink(2) blah blah blah explain_readlink_or_die(3) blah blah blah and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2008 Peter Miller explain_readlink(3)
All times are GMT -4. The time now is 10:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy