Sponsored Content
Top Forums Shell Programming and Scripting Very strange things happened in the shell function Post 302180123 by tpltp on Saturday 29th of March 2008 11:38:39 PM
Old 03-30-2008
Very strange things happened in the shell function

Here is the script:

Code:
#!/bin/bash
#set -xv
RAWDATAFILE="temp1"
GOODDATAFILE="temp2"
FindSOS()
{
local NUM=0 #return value for the id of SOS
local cnt=1
if grep "EOS" $1
then
sed -e 's/.*<CobDate>//' -e 's/<\/.*//' <$1 > ${RAWDATAFILE}
sed -n -e '/EOS/,/SOS/ s/[0-9]*/&/p' <${RAWDATAFILE} >${GOODDATAFILE}
NUM=`more ${GOODDATAFILE} |sed -e 's/<EOS\/>//' -e 's/<SOS\/>//' |grep -v '^$'`
else            #The <SOS/> must be in the second line, the required EID is in the
                # first line
while read line
do
if [ ${cnt} -eq 1 ]; then
eval NUM=${line}
break
fi
cnt=$(($cnt+1))
done <$1

fi

echo $NUM
}

echo $NUM
exit 0

Here is the result:
Code:
./FindSOS.ksh sosofile
RAWDATAFILE="temp1"
+ RAWDATAFILE=temp1
GOODDATAFILE="temp2"
+ GOODDATAFILE=temp2
FindSOS()
{
local NUM=0 #return value for the id of SOS
local cnt=1
if grep "EOS" $1
then
sed -e 's/.*<CobDate>//' -e 's/<\/.*//' <$1 > ${RAWDATAFILE}
sed -n -e '/EOS/,/SOS/ s/[0-9]*/&/p' <${RAWDATAFILE} >${GOODDATAFILE}
NUM=`more ${GOODDATAFILE} |sed -e 's/<EOS\/>//' -e 's/<SOS\/>//' |grep -v '^$'`
else            #The <SOS/> must be in the second line, the required EID is in the
                # first line
while read line
do
if [ ${cnt} -eq 1 ]; then
eval NUM=${line}
break
fi
cnt=$(($cnt+1))
done <$1

fi

echo $NUM
}
id=`FindSOS $1`
FindSOS $1
++ FindSOS sosofile
++ local NUM=0
++ local cnt=1
++ grep EOS sosofile
++ sed -e 's/.*<CobDate>//' -e 's/<\/.*//'
++ sed -n -e '/EOS/,/SOS/ s/[0-9]*/&/p'
more ${GOODDATAFILE} |sed -e 's/<EOS\/>//' -e 's/<SOS\/>//' |grep -v '^$'
+++ more temp2
+++ sed -e 's/<EOS\/>//' -e 's/<SOS\/>//'
+++ grep -v '^$'
++ NUM=2080370166
++ echo 2080370166
+ id='<EOS/>
2080370166'
echo $id
+ echo '<EOS/>' 2080370166
<EOS/> 2080370166
exit 0
+ exit 0

I feel strange about that in the function, the NUM=2080370166, but why out of the function, id get the value, the value changes to "<EOS/> 2080370166"

Did I miss something here? Thank you
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Gnome doing strange things.

I dual-booted a Pentium 166 with 48mbs of RAM and 2 gig HD between Windows 95 and Redhat 7. I installed the workstation setup, and selected Gnome as my GUI. Everything went fine, setup was great, no bugs. My monitor is ancient, so it was in the monitor list, and I entered my VRAM as 1mb. All... (5 Replies)
Discussion started by: Furtoes00
5 Replies

2. Linux

Strange problem with gettimeoftheday function

Hi all, I am using pthread_cond_timedwait function in my program, to generate the time period of waiting i use gettimeoftheday function. When i run the code after compiling i get a core dump error. However my program runs perfectly if i give a printf statement before the gettimeoftheday... (1 Reply)
Discussion started by: xyz123456
1 Replies

3. Solaris

unable to format usb stick ?strange things happening as well!!!

Hi all, I have a pendrive that is fat formatted... It was being detected so far on solairs...but now during the re-installation of solaris ,i did not remove the drive and guess i screwed it up... since then , i am unable to use it...guess its now not formatted or is corrupt... but the irony... (3 Replies)
Discussion started by: wrapster
3 Replies

4. UNIX and Linux Applications

strange behavior of PSQL user defined function

Segregated the problematic portion, and showing for your view here., 1. Following is the function definition, create or replace function new_del(id integer) returns void as $$ begin raise info 'dollar :%',$1; delete from testing where id=$1; end ; $$ language 'plpgsql'; ... (1 Reply)
Discussion started by: thegeek
1 Replies

5. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

6. Shell Programming and Scripting

Shell script that will do two things at once

I am trying to script up a build of my system from source, and the first couple of steps requires me to do a pull from a CVS mirror three times, and then the script begins. What I'd like is to be able to do one CVS pull, then start the build of userland, and while userland is building, pull down... (1 Reply)
Discussion started by: brakeb
1 Replies

7. Shell Programming and Scripting

Strange errors with shell scripts..plzz help

Hi all... Please help me with this questions. I am not good at shell scripting. 1) It seems like there are many ways that we can run the shell scripts. what is the difference between each one? i)./shell_script.sh ii).(space)./ shell_script.sh iii)sh shell_script.sh ... (3 Replies)
Discussion started by: sanskumar2003
3 Replies

8. UNIX for Beginners Questions & Answers

Strange things happen when I close my laptop lid

I recently bought a new HP Spectre x360 laptop and installed Linux (Ubuntu 16.04 LTS 64 bit) for the first time. I have noticed a few small bugs but something very strange happens when I shut the laptop lid. The last time I closed it for example, when I re-opened: The screen resolution had... (0 Replies)
Discussion started by: twelth_hour
0 Replies

9. Shell Programming and Scripting

Strange function call in the shell script parse_prog_args $@

I am converting shell script to Perl. In shell I have a code parse_prog_args() { if then while do case $1 in -P* | -p* ) export PROCESS_DATE=$2 export MM=`echo $2 | cut -c5-6` export DD=`echo $2 | cut -c7-8` export YY=`echo $2 | cut -c3-4` export... (4 Replies)
Discussion started by: digioleg54
4 Replies

10. Shell Programming and Scripting

Strange third argument in shell function

In one of my shell function I found the following set_default_values () { prog=$1 PROC_DT=$2 RESET_ALL="${3-N}" #echo "Processing date as passed = , Program name = " ...... I understand the first and second arguments, but don't understand... (1 Reply)
Discussion started by: digioleg54
1 Replies
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a filename containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 06:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy