LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-03-2013, 10:31 AM   #1
masonje
LQ Newbie
 
Registered: Mar 2013
Distribution: Ubuntu
Posts: 9

Rep: Reputation: Disabled
characters getting replaced with spaces in shell script


I'm getting the strangest behavior in my script. I can echo the line in the script and that works fine. I see the output as I would expect. However on some lines (and the file doesn't have any strange characters in it) when I use that $line variable in a command, some characters are being replaced with spaces. Here is the code:

Code:
#!/bin/bash

set -x 

file="vms.txt"
while read line           
do 
	echo "Line: $line"
	if VBoxManage list vms | grep \"$line\" > /dev/null 2>&1
		then
		echo "Found VM: $line"
		VMS=$(VBoxManage showvminfo ${line} | grep "State:")
		echo $VMS
	else
		echo "Virtual Machine Not found: $line"
	fi     
done <"${file}"
...but here is the output with the set -x on:

Code:
Found VM: DebianSQL
+ VBoxManage showvminfo DebianSQL
+ grep State:
+ VMS=State:           aborted (since 2013-01-14T04:54:26.000000000)
+ echo S a e:           abor ed ( ince 2013-01-14T04:54:26 000000000)
S a e:           abor ed ( ince 2013-01-14T04:54:26 000000000)
+ read line
+ echo Line: DebianMC
Line: DebianMC
+ VBoxManage list vms
+ grep "DebianMC"
+ echo Found VM: DebianMC
Found VM: DebianMC
+ VBoxManage showvminfo DebianMC
+ grep State:
+ VMS=State:           running (since 2013-03-02T17:23:13.831000000)
+ echo S a e:           running ( ince 2013-03-02T17:23:13 831000000)
S a e:           running ( ince 2013-03-02T17:23:13 831000000)
+ read line
+ echo Line: DebianTemplate
Line: DebianTemplate
+ VBoxManage list vms
+ grep "DebianTe pla e"
+ echo Virtual Machine Not found: DebianTemplate
Virtual Machine Not found: DebianTemplate
+ read line
SO you can see with the highlighted items, I'm getting some strange output. I tried setting the engine from /bin/bash and /bin/sh and that didn't make any difference.

Any idea what is causing this? I know the "DebianTemplate" is there, but when I grep with the variable set to that, somehow there is character substitution going on and the spaces make it look like a different VM name.
 
Old 03-03-2013, 10:51 AM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,437

Rep: Reputation: 599Reputation: 599Reputation: 599Reputation: 599Reputation: 599Reputation: 599
Looks like IFS (the shell's Internal Field Separators list) has been set to something strange that includes the characters "s", "t", and "m". Did you, perchance, unwisely choose that name for one of your variables?
 
  


Reply


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to replace a line with unknown spaces in a file using shell script RaviTezu Linux - Newbie 4 01-29-2013 10:02 AM
[SOLVED] linux shell script comparing strings containing spaces tinaelizabeth84 Linux - Newbie 2 06-28-2012 10:36 PM
problem with blank spaces in shell script argie01 Linux - Newbie 4 05-07-2010 04:54 AM
list filenames with spaces in a shell script xp_newbie Programming 6 03-15-2009 07:46 PM
replaced variable field within shell script using sed hamimi Linux - Newbie 2 05-28-2008 08:01 AM


All times are GMT -5. The time now is 03:23 AM.

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