www.unix.com
Open in
urlscan Pro
209.126.104.117
Public Scan
URL:
https://www.unix.com/shell-programming-and-scripting/12021-pass-parameter-back-calling-program.html
Submission: On September 01 via api from SG — Scanned from DE
Submission: On September 01 via api from SG — Scanned from DE
Form analysis
3 forms found in the DOMPOST https://www.unix.com/search.php?do=process
<form action="https://www.unix.com/search.php?do=process" method="post">
<input type="hidden" name="do" value="process">
<input type="hidden" name="quicksearch" value="1">
<input type="hidden" name="childforums" value="1">
<input type="hidden" name="exactname" value="1">
<input type="hidden" name="s" value="da7f4cc842b0e296888285338d3b7c89">
<input type="hidden" name="securitytoken" value="guest">
<input type="hidden" name="showposts" value="0" id="rb_nb_sp0_neo" tabindex="1002">
<div id="bs-search-bar" class="nav-top-margin" style="margin-bottom:20px;">
<div class="input-group">
<span class="input-group-addon"><button class="btn btn-light" style="background-color: #f0f0f7;border:1px solid silver;color:gray;"><i class="fas fa-search neo-toolbit" data-original-title="" title=""></i></button></span>
<input type="search" class="form-control" style="background-color: lightyellow" name="query" tabindex="1001" placeholder="Search The UNIX and Linux Forums (Quick Search)">
</div>
</div>
</form>
POST https://www.unix.com/search.php?do=process
<form action="https://www.unix.com/search.php?do=process" method="post">
<input type="hidden" name="do" value="process">
<input type="hidden" name="quicksearch" value="1">
<input type="hidden" name="childforums" value="1">
<input type="hidden" name="exactname" value="1">
<input type="hidden" name="s" value="da7f4cc842b0e296888285338d3b7c89">
<input type="hidden" name="securitytoken" value="guest">
<div>
<input type="text" class="bginput form-control" name="query" size="25" tabindex="1001">
</div>
<div style="margin:10px 0px 10px 0px;text-align:center;">
<input type="submit" class="button btn btn-primary btn-block" value="Search" tabindex="1004">
</div>
<div style="margin-top:6px">
<label for="rb_nb_sp0"><input type="radio" name="showposts" value="0" id="rb_nb_sp0" tabindex="1002" checked="checked" style="margin: 0px 5px 0px 0px;">Show Threads . </label> <label for="rb_nb_sp1"><input type="radio" name="showposts"
value="1" id="rb_nb_sp1" tabindex="1003" style="margin: 0px 5px 0px 0px;">Show Posts</label>
</div>
</form>
GET https://www.unix.com
<form action="https://www.unix.com" method="get">
<div style="padding:0px; margin:0px; border:0;width:100%;text-align:center;">
</div>
<div style="background-color:white;">
<br>
<div style="text-align:center; width:100%;background-color:white;">
<div class="smallfont" style="width:100%;background-color:white;padding-left:20px;padding-right:20px;">
<strong>
<span class="neo-footer-contactus"><a href="https://www.unix.com/sendmessage.php?s=da7f4cc842b0e296888285338d3b7c89" style="text-decoration:none;" rel="nofollow" accesskey="9">Contact Us</a></span>
<span class="neo-footer"> - <a href="https://www.unix.com/" style="text-decoration:none;">The UNIX and Linux Forums - unix commands, linux commands, linux server, linux ubuntu, shell script, linux distros.</a> -</span>
<span class="neo-footer"><a style="text-decoration:none;" href="https://buysellads.com/buy/detail/215189" rel="nofollow" accesskey="9">Advertising</a> - </span>
<a style="text-decoration:none;" href="https://www.unix.com/shell-programming-and-scripting/12021-pass-parameter-back-calling-program.html#top" onclick="self.scrollTo(0, 0); return false;"><span class="neo-footer">Top</span></a>
</strong>
</div>
</div>
</div>
</form>
Text Content
The UNIX and Linux Forums Forum Home Linux and Unix Man Pages Search Forums Search Community Posts Today's Posts Quick Links Man Pages RedHat Commands OpenSolaris Commands Linux Commands SunOS Commands FreeBSD Commands All UNIX Man Pages All Linux Man Pages Full Man Repository Login or Register to Ask a Question and Join Our Community Search Forums Show Threads . Show Posts Tag Search Advanced Search Quick Links Contact Us Forum Rules Today's Posts FAQ Pictures & Albums All Albums Miscellaneous What is My IP Whois Mark Forums Read SHELL PROGRAMMING AND SCRIPTING PASS PARAMETER BACK TO CALLING PROGRAM Tags beginners, shell scripts Login to Discuss or Reply to this Discussion in Our Community Page 1 of 2 1 2 > Thread Tools Search this Thread Top Forums Shell Programming and Scripting pass parameter back to calling program # 1 11-18-2003 jthomas Registered User 7, 0 Join Date: Nov 2003 Last Activity: 10 December 2003, 10:20 AM EST Posts: 7 Thanks Given: 0 Thanked 0 Times in 0 Posts pass parameter back to calling program -------------------------------------------------------------------------------- Hi all, I am running AIX version 4. I have a shell script that is calling another script. I want the called script to obtain a value and pass it back to the calling script. So far, I know that to pass a parameter to a called script is as such: sh proc2.sh $1 $2 etc. What I don't know how to do though is pass a parameter back the other way. Can any one help?? Thanks Jules jthomas View Public Profile for jthomas Find all posts by jthomas # 2 11-18-2003 Perderabo Administrator Emeritus 9,926, 461 Join Date: Aug 2001 Last Activity: 26 February 2016, 12:31 PM EST Location: Ashburn, Virginia Posts: 9,926 Thanks Given: 63 Thanked 461 Times in 270 Posts sh proc2.sh $1 $2 etc is really off to a bad start. It would be better to call it proc2 rather than proc2.sh. And invoking it via an explicit call to sh is a very bad idea. You should make the first line of proc2 something like: #! /usr/bin/sh (but use your path to sh) and then do a: chmod +x proc2 When you do these things you can then run proc2 as an executable: proc2 $1 $2 Now if the author of proc2 decides to rewrite it in c or ksh or perl etc, you don't need to change every script that called it. Famous unix program like "touch" and "grep" started out as sh scripts. Also $1 and $2 refer to the first and second positional parameters in the caller. It would be rare to pass those to a second program. Since you're using sh rather than ksh, you must be using expr for any arithmetic like this: x=1 x=`expr $x + 1` This is one way to return a parameter. The backticks take the stdout from the program. And the other way it the exit code, which is very limited. Here is a sample: #! /usr/bin/sh echo hello exit 2 And another script would do this: x=`sample` echo $x sample echo $? Perderabo View Public Profile for Perderabo Find all posts by Perderabo # 3 11-18-2003 mbb Registered User 104, 0 Join Date: Aug 2001 Last Activity: 25 October 2010, 3:31 AM EDT Location: UK Posts: 104 Thanks Given: 0 Thanked 0 Times in 0 Posts You can use the exit command to pass back an error number. e.g. exit 56 This value is passed back into the calling shell and can be examined in the built in variable $?. If you want to do something a little more complex (like a string) then the called script should echo the return value e.g. echo $SOME_VARIABLE. To use this value in the calling script: RETURN_VAR=`called_script param1 10 20` Notice the back quote(`). You are telling ksh to replace the results of the script into the variable i.e. what ever is echoed to stdout. You could also use syntax like: RETURN_VAR=$(called_script param1 10 20) If you want to pass back several parameters then echo them as one string, using a delimiter to separate the values. mbb View Public Profile for mbb Find all posts by mbb # 4 11-18-2003 jthomas Registered User 7, 0 Join Date: Nov 2003 Last Activity: 10 December 2003, 10:20 AM EST Posts: 7 Thanks Given: 0 Thanked 0 Times in 0 Posts I called the script like you said in the funny `` quotes. In the called program did the echo...all worked like a charm. Thanks MBB for that extra bit at the end, my very next question was in fact; "What about when you have more than 1 parameter"! Appreciate the help guys, thanks. jthomas View Public Profile for jthomas Find all posts by jthomas # 5 11-19-2003 linuxpenguin Registered User 350, 5 Join Date: May 2002 Last Activity: 28 March 2014, 4:09 PM EDT Location: India Posts: 350 Thanks Given: 0 Thanked 5 Times in 5 Posts how about this one echo $retval|awk -v x="YOUR OUTPUT" '{print substr(x,2,4)}' so you return the output of ur script using retval=`your script` and use retval as a variable to awk and the use the substring function of awk to split the output i know echo retval doesnt look elegant tho, but this is just a sample to hint you the use of awk and its substr function linuxpenguin View Public Profile for linuxpenguin Find all posts by linuxpenguin # 6 11-19-2003 linuxpenguin Registered User 350, 5 Join Date: May 2002 Last Activity: 28 March 2014, 4:09 PM EDT Location: India Posts: 350 Thanks Given: 0 Thanked 5 Times in 5 Posts probably if retval is 2 4 5 6 echo $retval|awk '{print substr($0,2,4)' this would result into " 4 6" linuxpenguin View Public Profile for linuxpenguin Find all posts by linuxpenguin # 7 11-20-2003 jthomas Registered User 7, 0 Join Date: Nov 2003 Last Activity: 10 December 2003, 10:20 AM EST Posts: 7 Thanks Given: 0 Thanked 0 Times in 0 Posts Thanks for the reply LP. I must admit, I know nothing about AWK. I have tried once or twice to use it, all I get are strange errors that I can't debug. My UNIX administrator don't even know how the command works. They gave me a book once that should have explained the awk procedure, but it was a piece of rubbish - couldn't make head or tails of it. I would love to be able to use the awk procecedure cos I understand that its really powerfull. Where do I go though to get a really good set of definitions of the syntax? Looking at your code I can understand what you are getting at, but I don't know the mechanics of what you are doing, e.g. what is the -v option and what other type of options are there, why do you print the results etc etc etc jthomas View Public Profile for jthomas Find all posts by jthomas Page 1 of 2 1 2 > Login or Register to Ask a Question Previous Thread | Next Thread 9 MORE DISCUSSIONS YOU MIGHT FIND INTERESTING 1. SHELL PROGRAMMING AND SCRIPTING HOW TO GET FRONT AND BACK PARAMETER OF EACH CHARACTERS? I have list of words file. I trying to get a front and back parameter of each characters of words. hello .... .... Here is what I have done: awk '{ word=$1; len=length(word); tlen=2*len-1; for (i=1; i<len; i++) a="#"; for (j=1; j<=len; j++) a=substr(word,j,1); ... (15 Replies) DISCUSSION STARTED BY: PARANRAT 15 Replies 2. SHELL PROGRAMMING AND SCRIPTING PASS PARAMETER Hi, I have following for loop , please let me know how to get ${TXP_EXT_TABLE_${i}_SQL} parameter with 1DAY and 7DAY values. for i in 1DAY 7DAY do ${NZSQL_DIR}/nzsql -h ${HOST} -time -v ON_ERROR_STOP=1 -f ${SQL_DIR}/${TXP_EXT_TABLE_${i}_SQL} > ${TMP_LOG_FILE} 2>&1 done ... (4 Replies) DISCUSSION STARTED BY: SANDY162 4 Replies 3. SHELL PROGRAMMING AND SCRIPTING HOW TO PASS THE ENVIRONMENT NAME WHILE CALLING JAVA PROGRAM FROM UNIX SCRIPT? Hi, I'm trying to test one unix shell script in dev environment. But I'm not sure how to pass the environment in my java program calling code. I'm trying to use -DconsumerEnv="DEV" but unfortunately I get 'null' while trying to print the value from java class. System.out.println("Environment: "+... (4 Replies) DISCUSSION STARTED BY: PRAMIT 4 Replies 4. UNIX FOR DUMMIES QUESTIONS & ANSWERS PASS VALUE BACK TO UNIX VARIABLE i had this unix korn shell code that connects to oracle database and execute the oracle procedure. i need to add a variable that indicates the oracle procedure failed. basically the variable is to check if the oracle procedure failed it will assign 1 and when the variable is equal to 1 it will not... (4 Replies) DISCUSSION STARTED BY: WTOLENTINO 4 Replies 5. HOMEWORK & COURSEWORK QUESTIONS CALLING COMPILED C PROGRAM WITH PERL PROGRAM Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply) DISCUSSION STARTED BY: JDKIRBY 1 Replies 6. UNIX FOR DUMMIES QUESTIONS & ANSWERS HOW TO PASS THE PARAMETER VALUE TO A... ? Hello I have a simple code like this one: #!/bin/ksh VER=$1 cat /usr/text | while read line do echo $line done Let's say $1=1.0.0 and the contents of text is: abcd.cfg asdf I would like the output to be like this abcd1.0.0.cfg asdf1.0.0 I am thinking of passing the... (5 Replies) DISCUSSION STARTED BY: KHESTOI 5 Replies 7. UNIX FOR DUMMIES QUESTIONS & ANSWERS CALLING PROCESS AND GOING BACK TO THE MAIN LOOP hi everyone , i want to read an option and depending on the option call the program .For ex #! /bin/ksh export JAVA_HOME=/home/oracle/jdk1.6.0_20 echo " Please enter mod-modeler, dev - sqldeveloper" read choice if ; then echo ' SQL DEVELOPER IS STARTING NOW ... ' cd... (0 Replies) DISCUSSION STARTED BY: KDEV 0 Replies 8. SHELL PROGRAMMING AND SCRIPTING HOW TO PASS A PARAMETER Hi all, How to pass a parameter from a oracle pl/sql procedure parameter to shell environment and use it? (1 Reply) DISCUSSION STARTED BY: MEGH 1 Replies 9. SHELL PROGRAMMING AND SCRIPTING HELP REQUIRED TO PASS THE PARAMETER i am calling a pl/sql procedure through a shell script, there is one IN and 2 OUT parameter required to pass to the procedure to execute.. My procedure is XX_CITIDIRECT_EXP_PKG.main_proc and In parameter is p_period which I wanto to pass 'MAY-06'. Can anyone figure out, whats is wrong here ... (4 Replies) DISCUSSION STARTED BY: U263066 4 Replies Login or Register to Ask a Question MEMBER BADGES AND INFORMATION MODAL × Close FEATURED TECH VIDEOS Powered By 10 Videogames, Minecraft: i 10 materiali più difficili da trovare e come recuperarli Share Next Stay All times are GMT -4. The time now is 09:52 PM. Contact Us - The UNIX and Linux Forums - unix commands, linux commands, linux server, linux ubuntu, shell script, linux distros. - Advertising - Top Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved. Privacy Policy