Issue with accessing value inside while loop, outside it
Hi,
Even though i have declared the variable outside the while loop, the changing value inside the while loop never reflects outside it
Always getting the error as : "This is not a valid market... Exiting", even if the name is proper & exists in the list. Inside the while loop it gets set to 1, but outside during the "if" check it takes up the 0 value.
I would have to use Korn Shell, as am using some other symtax in rest of the code which is not compatible with bash
I tried the once you have mentioned above, but its not working (because of shell maybe)
Is there any equivalent in korn shell that I can use?
Thanks,
Ritu
OK. In that case I would suggest to set xtrace / verbose and run your script to help understand what exactly is happening at that if statement:
Another option is using grep command:
It is really strange! I don't see below echo statement anywhere in the code that you posted:
Also I don't understand why the script continues to run after exit statement! Are you calling this function from another script?
Even though i have declared the variable outside the while loop, the changing value inside the while loop never reflects outside it
Always getting the error as : "This is not a valid market... Exiting", even if the name is proper & exists in the list. Inside the while loop it gets set to 1, but outside during the "if" check it takes up the 0 value.
Could someone please help
Thanks,
Sorry, but I don't believe your statement:
Quote:
Always getting the error as : "This is not a valid market... Exiting", even if the name is proper & exists in the list.
With your code, if the name entered exactly matches a line in names.txt, the function you had exits before it gets to the point that echoes:
Quote:
This is not a valid name... Exiting
When you find a match, you call exit which terminates the while loop, the function, and the shell script that called the function. When you don't find a match, you call exit which terminates the function and the script that called the function. I would think you would want something more like the following:
Without knowing the environment in which this function will be used, I would have expected the exit at the end of this function to be either:
if you really want to exit the script calling this function indicating unsuccessful completion, or:
indicating that the function failed, but letting the rest of the script continue if it wants to based on the return value from the function. I used exit 1 in my rewrite to follow the statement in your last echo.
Furthermore, I didn't see any need for tempvar, since Name is always valid if $abc is not "SO" and this function returns to the calling program (after my changes) and can never be used if the name is not found (since your program exits).
Hi Guys,
I need to access multiple directories whcih is following similar structure and need to copy those files in desitination path.
for eg :
if ]
then
cd ${DIR}/Mon/loaded
echo "copying files to $GRS_DIR"
cp * ${DIR}/Mon/
echo "Files of Monday are Copied"
fi
if ]
then... (5 Replies)
Hi ,
I'm trying to move/copy the files inside the loop into a directory .
I tried the below code and the issue is the data is not copying into the created directory but the files are copying into another file
file_path="/home/etc"
Last_Day=20130930
mkdir $file_path/ARC_${Last_Day}
... (3 Replies)
Hi all,
Here is an outline of the problem:
#variable declared at start of script
x=0;
#a function that increments x by 1 every 10 seconds
incrementX(){
increments x every 10 seconds;
}
#i want this to output the value of x every second. The problem is that x is always reported... (3 Replies)
Hi all
Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Hi All,
I have some files in my directory, and i want to pull all data using for loop....I am using following code but getting error..!
for file in {file1, file2, file3, ..... filen}
do
L="$(tail -1 $file)";NUM=${L%%|*};DAT=${L##*|}
echo $NUM>>filedata.txt
done
Error:
tail:... (3 Replies)
I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends.
As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
I have a file (email) containing email addresses.
I have a second file (terms) that contains simple regular expressions and words/characters. Here are some examples:
\.trainee
\.group
\.web
I want to go through email and delete lines containing the expressions/words from terms and write... (1 Reply)
hi,
Is there a way to access the redirected file inside the script. Here is what the command line looks like:
$ shar * > archive_file.arc
I know I can't access the name of archive_file.arc with positional parameters like $1, $2.. Is there any way to figure out what file the output of the... (3 Replies)