Register
It is currently Sat Oct 25, 2014 5:50 am

Awful echo side effect


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Wed May 25, 2011 4:56 am   
User avatar

Joined: Sun Nov 01, 2009 8:59 am
Posts: 25
Location: Try to guess!
Hello,
just came across a strange and irritating side effect of echo today, while `tr`ing a C source file and echoing the result into another. Just after
Code:
string=`cat boot.c | tr '\n' ' '`

an extract of $string looks like this (courtesy of bash -x):
Code:
initTcbs();   /**************** SSI ****************/ /*Thread control block pointer

which is correct, BUT if i try to echo it... the result is this (same part as above):
Code:
initTcbs(); /bin /boot /cdrom /dev /etc /home /initrd.img /lib /lost+found /media /mnt /opt /proc /root /sbin /selinux /srv /sys /tmp /usr /var /vmlinuz SSI home docs/ openrg/ programming/ prints/ /*Thread control block pointer

As you can see /* (start of comment) and * (after "SSI") will cause echo to print my root dir and my $PWD (desktop in this case), respectively. But not the "/*Thread control block pointer" comment which follows.
What the heck is wrong with me?


Top
 Profile  
 PostPosted: Wed May 25, 2011 8:04 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Read Pathname Expansion in man bash if you want to know why. Use
Code:
echo "$string"
(i.e. double quotes)


Top
 Profile  
 PostPosted: Wed May 25, 2011 9:32 am   
User avatar

Joined: Sun Nov 01, 2009 8:59 am
Posts: 25
Location: Try to guess!
I've just realized how dumb i am... x_x
Sepukku time or maybe i just need some more sleep? x_x
Anyway i can justify this: it's been almost two years since my last bash script... looks like i'm forgetting a lot of important things!
Ok then... now where did i put that "Advanced Bash Scripting Guide"?


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP