Re: Add to text file from command line via echo... possible to add to a particular line?[Scanned]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thursday, Jun 29th 2006 at 17:37 +0100, quoth Chris Bradford:

=>Paul Howarth wrote:
=>> On Thu, 2006-06-29 at 16:07 +0100, Chris Bradford wrote:
=>>   
=>> > Paul Howarth wrote:
=>> >     
=>> > > On Thu, 2006-06-29 at 07:42 +0100, Chris Bradford wrote:
=>> > >         
=>> > > > [much unimportant stuff deleted]
=>> > > >             
=>> > > How about:
=>> > > 
=>> > > [same here]
=>> > >         
=>> > Paul,
=>> > 
=>> > [not even vaguely relevant]
=>> >     
=>> 
=>>   
=>Any ideas as to why this:
=>
=>echo -n "Would you like to configure SophosAV: (type yes/no) "
=>read ANSWER
=>
=>if [ $ANSWER = yes -o YES ]
=>then
=>   echo 'good'
=>   echo 'Enter script to run here....'
=>
=>else
=>   echo 'bad'
=>   echo 'Carry on to next part of current script...'
=>fi
=>
=>Does not work?
=>
=>Thanks,
=>
=>-Chris

I'm guessing this should have been a new message and not a reply to an old 
message.

As you've already heard

[ $ANSWER = yes -o YES ]

is not the same as 

[ $ANSWER = yes -o $ANSER = YES ]

But what happens if the keyboard monkey would have hit return?

Then the value of ANSWER would have been null, in which case the variable 
would have expanded to null and the shell would have executed

[ = yes -o = YES ] 

which would have been a syntax error. So a better answer would be:

[ "$ANSWER" = yes -o "$ANSER" = YES ]

BUT! baash has something even better. The [ syntax is old. Instead, use 
the double squarebrace syntax.

[[ "$ANSWER" = yes || "$ANSER" = YES ]]

Better, faster, more readable.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux