Sponsored Content
Top Forums Shell Programming and Scripting bash shell: 'exec', 'eval', 'source' - looking for help to understand Post 302169863 by alex_5161 on Friday 22nd of February 2008 03:37:57 PM
Old 02-22-2008
jim mcnamara -
thank you, very much, everything clear and usefull for me now!

I am realy exiting to understand it. Now I have new (for me ) possibility in scripting and in shell.
Definetely, 'eval' gives usefull opportunity!
The 'exec' - nice to know that and it is good to use it, too.
The 'sorce' - it appeared that I have used it already for long time (as '. script') but did not realized tha all definishions of the curent shell are available in runing script by that (other part - backward - usualy is a reason to use the '. scr')
I've just tryed it and maybe it would be usefull to show it here, too, although your explanation pretty enough, but, anyway, here it is:

Code:
bash-802:/home/dca0701/develop/src> cat > try.sh
/usr/bin/echo "\n -- try to use already defined in shell alias:"
ec "<<< this printed by shell alias 'ec'"

shopt -s expand_aliases
alias ec2=ec
ec "--- new alias is declared as ec2"
^C
bash-803:/home/dca0701/develop/src>
bash-803:/home/dca0701/develop/src> chmod 777 try.sh
bash-804:/home/dca0701/develop/src>
bash-804:/home/dca0701/develop/src>
bash-804:/home/dca0701/develop/src> try.sh

 -- try to use already defined in shell alias:
./try.sh: ec: command not found
./try.sh: ec: command not found
bash-805:/home/dca0701/develop/src>
bash-805:/home/dca0701/develop/src> source try.sh

 -- try to use already defined in shell alias:
<<< this printed by shell alias 'ec'
--- new alias is declared as ec2
bash-806:/home/dca0701/develop/src> ec2 hello
hello
bash-807:/home/dca0701/develop/src>

Once again, thank you very much!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

difference between source, exec and ./script

What is the difference between sourcing a script, running it or execing it? (1 Reply)
Discussion started by: 98_1LE
1 Replies

2. Shell Programming and Scripting

exit status of eval exec

I am using ksh88 and I am trying to catch the return status of opening a file using a file descriptor and the exec and eval commands. However I am not having much success. Here is what I have: eval "exec $next_fh>$1" This opens the file if the file is $1 is valid, however I want to make... (1 Reply)
Discussion started by: robotball
1 Replies

3. Shell Programming and Scripting

Exec bash shell via PHP Site !

Hi everybody ! I writed php code so exec bash shell via php (SMS Send via bash shell) but i have problem as follow : 1. When i exec from linux mode : ./sms.sh --- output is "Messages ... OK". Then all message has been sent. 2. When i exec from PHP site --- return value is "Message ... OK" on... (1 Reply)
Discussion started by: lamthenhan
1 Replies

4. Programming

help me understand exec() family of calls...

how does exec() do it? on successful call of exec() family of functions, they never return... how to i emulate that. assume the standard example, execl("/bin/ls","ls",NULL); now this would never return. i m trying to emulate exec()'s never to return feature... #include<unistd.h>... (4 Replies)
Discussion started by: c_d
4 Replies

5. Shell Programming and Scripting

I need to understand the differences between the bash shell and the Bourne shell

I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done. I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
Discussion started by: awk_sed_hello
7 Replies

6. Programming

Need help with this c++ source code! DOnt understand what some stuff mean.

Okay so I am just starting programming c++. I just started started to red "C++ for Dummies yesterday and theres a lot of things I do not understand from this book and this source code especially. I will first post the full source code and then post questions about certain thing, usually what they... (2 Replies)
Discussion started by: orszhak
2 Replies

7. Shell Programming and Scripting

Not able to understand use exec command

Hi i am in learning phase of unix. i was going through exec in a unix book. below is the command exec n>file exec n>>file however when i used the exec command like below , where ex is the file name exec 2>>exand then do ls -lrt then again when i do the ls -lrt to see the size of the file... (3 Replies)
Discussion started by: scriptor
3 Replies

8. Programming

Help me to understand strange 'typedef ... ' in some source...

Working on some source I've found some strange declaration in included header file. I am looking for someone's help to understand me that syntax's, as it is fine (it is compiled without any complain,) but for me it seems out of any sense! Acctually, it warning by CC compiler: " Warning: Implicit... (1 Reply)
Discussion started by: alex_5161
1 Replies

9. Shell Programming and Scripting

Shell Script Comment code blocks in a bash source file

Just began to learn on Shell Script. I got an exercise from my friend. I know how to make this happen in C, but I'm not familiar with Shell Script. Hope I can get some help from all of you. I want to write a bash script to comment code blocks in a bash source file. What I mean comment is '#', I... (1 Reply)
Discussion started by: HiFuture0801
1 Replies

10. Shell Programming and Scripting

How to understand special character for line reading in bash shell?

I am still learning shell scripting. Recently I see a function for read configuration. But some of special character make me confused. I checked online to find answer. It was not successful. I post the code here to consult with expert or guru to get better understanding on these special characters... (3 Replies)
Discussion started by: duke0001
3 Replies
ATF-SH(1)						    BSD General Commands Manual 						 ATF-SH(1)

NAME
atf-sh [-s shell] -- interpreter for shell-based test programs SYNOPSIS
atf-sh script DESCRIPTION
atf-sh is an interpreter that runs the test program given in script after loading the atf-sh(3) library. atf-sh is not a real interpreter though: it is just a wrapper around the system-wide shell defined by ATF_SHELL. atf-sh executes the inter- preter, loads the atf-sh(3) library and then runs the script. You must consider atf-sh to be a POSIX shell by default and thus should not use any non-standard extensions. The following options are available: -s shell Specifies the shell to use instead of the value provided by ATF_SHELL. ENVIRONMENT
ATF_LIBEXECDIR Overrides the builtin directory where atf-sh is located. Should not be overridden other than for testing purposes. ATF_PKGDATADIR Overrides the builtin directory where libatf-sh.subr is located. Should not be overridden other than for testing purposes. ATF_SHELL Path to the system shell to be used in the generated scripts. Scripts must not rely on this variable being set to select a specific interpreter. EXAMPLES
Scripts using atf-sh(3) should start with: #! /usr/bin/env atf-sh Alternatively, if you want to explicitly choose a shell interpreter, you cannot rely on env(1) to find atf-sh. Instead, you have to hardcode the path to atf-sh in the script and then use the -s option afterwards as a single parameter: #! /path/to/bin/atf-sh -s/bin/bash ENVIRONMENT
ATF_SHELL Path to the system shell to be used in the generated scripts. SEE ALSO
atf-sh(3) BSD
September 27, 2014 BSD
All times are GMT -4. The time now is 01:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy