Sponsored Content
Top Forums Shell Programming and Scripting How to make variables in script function local? Post 302173483 by vgersh99 on Thursday 6th of March 2008 07:49:03 PM
Old 03-06-2008
Code:
func1()
{
  typeset var1="asd-func1()"
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

shell script, reading and resetting local variables

Hello, I have a problem with trying to run a shell script that reads in user input, validates, and sets to a 'default' value if the input is not valid. I cannot get the portion of resetting to a default value to work. These lines are skipped, and the value of x is still whatever the user... (1 Reply)
Discussion started by: b888c
1 Replies

2. Shell Programming and Scripting

passing variables to sed function in a script ....

Hello , I have a script named testscript.sh wherein I have two variables $var and $final (both of which contain a number) I have a sed write function inside this script as follows: sed '1,2 w somefile.txt' fromfile.txt Now , in the above i want to pass $var and $final instead of... (2 Replies)
Discussion started by: shweta_d
2 Replies

3. Homework & Coursework Questions

I need to make a script that has 4 command line arguments to function properly.

I have no idea what the following means. The teacher is too advanced for me to understand fully. We literally went from running a few commands over the last few months to starting shell scripting. I am not a programmer, I am more hardware oriented. I wish I knew what this question was asking... (3 Replies)
Discussion started by: Wookard
3 Replies

4. Shell Programming and Scripting

remotely call function from local script

The following code doesn't work properly which means it doesn't displays remote output. #!/bin/ksh #################### Function macAddressFinder ######################## macAddressFinder() { `ifconfig -a > ipInterfaces` `cat ipInterfaces` }... (2 Replies)
Discussion started by: presul
2 Replies

5. UNIX for Advanced & Expert Users

How to make the variables of one script available for the other scripts?

Hello Everyone, I want to know how can we make the variables of one script available for the other script? for example i have three scripts variable_availability.sh,first.sh,second.sh and a file containing variables called common ---------------------------------- cat variable_availability.sh... (2 Replies)
Discussion started by: Kesavan
2 Replies

6. Programming

Thread function local variables

As I know threads share the memory. But, what about the local variables in the thread function? if i call multiple threads would they allocate seperate local variables for themselves? like thread_func() { int i, j; string... } Are the above local variables defined for each of... (1 Reply)
Discussion started by: saman_glorious
1 Replies

7. UNIX for Advanced & Expert Users

Script to make a table from Named Variables.

I need a shell script to make a table from Named Variables Input File(Can have multiple lines): a=1,b=2,d=4,e=5 a=11,b=12,c=13,d=14 Output file: a,b,c,d,e 1,2,,4,5 11,12,13,14, Thanks in advance (7 Replies)
Discussion started by: shariramani
7 Replies

8. Shell Programming and Scripting

How to make nested function local?

Hi, If I declare a function inside another function, it overwrites any previously declared function with the same name. This is NOT what I want. Example: #!/bin/bash _test() { echo test; } _myf() { # I'm using the same name as the other function. _test() { echo local test; }... (8 Replies)
Discussion started by: chebarbudo
8 Replies

9. UNIX for Beginners Questions & Answers

How to have local shell variables in a ksh script seen on remove server in SSH block?

I have googled this and found many solutions, but none of them are working for me. I am in a korn shell, most others reference bsh, maybe that is the issue? Anyway, all I am trying to do is use a variable I have declared in my main script in a remote shell I am running through ssh. So I have a... (8 Replies)
Discussion started by: DJR
8 Replies

10. Shell Programming and Scripting

Function - Make your function return an exit status

Hi All, Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition. #Body function1() { if then echo "exist" else echo "not exist" } #if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies
MAKECONTEXT(3)						     Linux Programmer's Manual						    MAKECONTEXT(3)

NAME
makecontext, swapcontext - manipulate user context SYNOPSIS
#include <ucontext.h> void makecontext(ucontext_t *ucp, void (*func)(), int argc, ...); int swapcontext(ucontext_t *oucp, ucontext_t *ucp); DESCRIPTION
In a System V-like environment, one has the type ucontext_t defined in <ucontext.h> and the four functions getcontext(3), setcontext(3), makecontext() and swapcontext() that allow user-level context switching between multiple threads of control within a process. For the type and the first two functions, see getcontext(3). The makecontext() function modifies the context pointed to by ucp (which was obtained from a call to getcontext(3)). Before invoking make- context(), the caller must allocate a new stack for this context and assign its address to ucp->uc_stack, and define a successor context and assign its address to ucp->uc_link. When this context is later activated (using setcontext(3) or swapcontext()) the function func is called, and passed the series of integer (int) arguments that follow argc; the caller must specify the number of these arguments in argc. When this function returns, the successor context is activated. If the successor context pointer is NULL, the thread exits. The swapcontext() function saves the current context in the structure pointed to by oucp, and then activates the context pointed to by ucp. RETURN VALUE
When successful, swapcontext() does not return. (But we may return later, in case oucp is activated, in which case it looks like swapcon- text() returns 0.) On error, swapcontext() returns -1 and sets errno appropriately. ERRORS
ENOMEM Insufficient stack space left. VERSIONS
makecontext() and swapcontext() are provided in glibc since version 2.1. CONFORMING TO
SUSv2, POSIX.1-2001. POSIX.1-2008 removes the specifications of makecontext() and swapcontext(), citing portability issues, and recommend- ing that applications be rewritten to use POSIX threads instead. NOTES
The interpretation of ucp->uc_stack is just as in sigaltstack(2), namely, this struct contains the start and length of a memory area to be used as the stack, regardless of the direction of growth of the stack. Thus, it is not necessary for the user program to worry about this direction. On architectures where int and pointer types are the same size (e.g., x86-32, where both types are 32 bits), you may be able to get away with passing pointers as arguments to makecontext() following argc. However, doing this is not guaranteed to be portable, is undefined according to the standards, and won't work on architectures where pointers are larger than ints. Nevertheless, starting with version 2.8, glibc makes some changes to makecontext(), to permit this on some 64-bit architectures (e.g., x86-64). EXAMPLE
The example program below demonstrates the use of getcontext(3), makecontext(), and swapcontext(). Running the program produces the fol- lowing output: $ ./a.out main: swapcontext(&uctx_main, &uctx_func2) func2: started func2: swapcontext(&uctx_func2, &uctx_func1) func1: started func1: swapcontext(&uctx_func1, &uctx_func2) func2: returning func1: returning main: exiting Program source #include <ucontext.h> #include <stdio.h> #include <stdlib.h> static ucontext_t uctx_main, uctx_func1, uctx_func2; #define handle_error(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0) static void func1(void) { printf("func1: started "); printf("func1: swapcontext(&uctx_func1, &uctx_func2) "); if (swapcontext(&uctx_func1, &uctx_func2) == -1) handle_error("swapcontext"); printf("func1: returning "); } static void func2(void) { printf("func2: started "); printf("func2: swapcontext(&uctx_func2, &uctx_func1) "); if (swapcontext(&uctx_func2, &uctx_func1) == -1) handle_error("swapcontext"); printf("func2: returning "); } int main(int argc, char *argv[]) { char func1_stack[16384]; char func2_stack[16384]; if (getcontext(&uctx_func1) == -1) handle_error("getcontext"); uctx_func1.uc_stack.ss_sp = func1_stack; uctx_func1.uc_stack.ss_size = sizeof(func1_stack); uctx_func1.uc_link = &uctx_main; makecontext(&uctx_func1, func1, 0); if (getcontext(&uctx_func2) == -1) handle_error("getcontext"); uctx_func2.uc_stack.ss_sp = func2_stack; uctx_func2.uc_stack.ss_size = sizeof(func2_stack); /* Successor context is f1(), unless argc > 1 */ uctx_func2.uc_link = (argc > 1) ? NULL : &uctx_func1; makecontext(&uctx_func2, func2, 0); printf("main: swapcontext(&uctx_main, &uctx_func2) "); if (swapcontext(&uctx_main, &uctx_func2) == -1) handle_error("swapcontext"); printf("main: exiting "); exit(EXIT_SUCCESS); } SEE ALSO
sigaction(2), sigaltstack(2), sigprocmask(2), getcontext(3), sigsetjmp(3) COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2013-02-12 MAKECONTEXT(3)
All times are GMT -4. The time now is 10:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy