Register
It is currently Fri Oct 24, 2014 5:19 am

Problem with redirection


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Thu Aug 02, 2012 9:34 am   

Joined: Thu Aug 02, 2012 9:29 am
Posts: 2
Hi,

I try to wrote a little script.

When _DEBUG=="off", the last 2 lines
are executed. But, when _DEBUG=="on"
the last 2 lines should give on the
console :
mv toto tata
cat tata >> tutu


Now, i get only the first line :
mv toto tata

and also :
$ cat tutu
cat tata

The problem seems to be with the redirection (>>).

How can i modify my script to reach my goal ?

Thank you.

Guy

Code:
#!/bin/bash

_DEBUG="on"
function DEBUG()
{
[ "$_DEBUG" == "on" ] && echo -E "$@"
[ "$_DEBUG" == "off" ] && $@
}
#_DEBUG="off"
cd /tmp
echo "test" > toto
DEBUG mv toto tata
DEBUG cat tata >> tutu


Top
 Profile  
 PostPosted: Thu Aug 02, 2012 10:27 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
hi,

that's the output of the function that is redirected to file tutu.
it's just like
Code:
_F() { echo 'any or other things';}
_F >> output.file
unfortunately, I don't know what to do :(


Top
 Profile  
 PostPosted: Fri Aug 03, 2012 8:53 am   

Joined: Thu Aug 02, 2012 9:29 am
Posts: 2
Thank you.
This is the way i fix this problem :

Code:
#!/bin/bash

_DEBUG="on"
function DEBUG()
{
[ "$_DEBUG" == "on" ] && echo -E "$@"
[ "$_DEBUG" == "off" ] && eval "$@"
}
_DEBUG="off"
cd /tmp
echo "test" > toto
DEBUG "mv toto tata"
DEBUG "cat tata >> tutu"


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:  


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