Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-04-2012, 06:18 AM   #1
Registered: Sep 2011
Posts: 55

Rep: Reputation: Disabled
some strange problem with return data in sctipt

I have come across a little strange problem in my script. i tried the same logic in some other script where its working fine. but in other script its not behaving as expected.
Here is the code:

cd /root/Test_project/Files/$catalog_name
for file in $run_count"_"*.csv; do
 echo $file
 file_count=`grep -c "." $file`
 echo $file_count"file_count \n"
 Count_file=$(awk -F"=" '{ ()print $1; }' $FILE_NAME )
 echo "file count= "$Count_file
 Count=`cat ${FILE_NAME} | grep ${PROP_KEY} | cut -d'=' -f2`

 echo $Count  #[Here its working fine, its showing the correct values which is returned from top]
 echo $Count"hi" #[here if i'm printing something with it then the value of $Count is lost. and its only printing hi] don't know why
#and based on that furhter logic is not working which is under if

if [ "$Count" == "$file_count" ]; then
 echo "column header count row proper"
 echo "Error send a mail as count is not correct in "$file
 exit 1
exit 0
My question is this
1. Why the value is lost of $Count when am trying to print something with it.
2. Is there any problem of data type?
3. What type of datatype is returned by cut command in above?
Here I need to return integer and then to compare them
Count is the number of files, which is specified in a property file from where its picking in above case.
file_count is number of rows in a file.

I need to compare them both and then have to take action further.
Help me out if there is something wrong with data type or logic or something else.

Old 01-04-2012, 09:25 AM   #2
Registered: May 2001
Posts: 29,393
Blog Entries: 55

Rep: Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565
The value of $Count is lost because you used an unprotected variable name ($Count"hi" instead of "${Count}hi"). To find out which values get assigned run the script as '/bin/bash -vx /path/to/script'. To compare integers you can use [ $Count == $file_count ] or [ $Count -eq $file_count ].

You should not test scripts as root user and not use unprotected, odd case or inconsistently named variable names.

function help() { echo "Bash scripting guides:"; }


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
NetSnmp exec script return data type hemulll Linux - Networking 8 11-28-2011 08:00 AM
Pseudo Terminal needs return before reading data MrUmunhum Programming 6 11-22-2008 03:10 PM
Serial port return wrong data levka Programming 3 04-13-2007 02:54 AM
Qt dialogs return data Ephracis Programming 7 02-21-2007 12:49 PM
Strange behavior: string within scope return 0 if not within a while loop. RHLinuxGUY Programming 2 08-06-2006 12:05 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:40 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration