Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 03-03-2013, 11:31 AM   #1
LQ Newbie
Registered: Mar 2013
Distribution: Ubuntu
Posts: 12

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:


set -x 

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

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, 11:51 AM   #2
Senior Member
Registered: Aug 2009
Distribution: CentOS
Posts: 2,165

Rep: Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900
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?


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 11:02 AM
[SOLVED] linux shell script comparing strings containing spaces tinaelizabeth84 Linux - Newbie 2 06-28-2012 11:36 PM
problem with blank spaces in shell script argie01 Linux - Newbie 4 05-07-2010 05:54 AM
list filenames with spaces in a shell script xp_newbie Programming 6 03-15-2009 08:46 PM
replaced variable field within shell script using sed hamimi Linux - Newbie 2 05-28-2008 09:01 AM

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

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