[sf-lug] Need help with an Linux assignment script

jim jim at well.com
Tue Apr 29 08:10:59 PDT 2008

good catch, clyde! 

i tried 
$ if "$( "tim" = "xxx" )" ; then 
> echo fooey 
> fi 
bash: tim : command not found 
bash: : command not found 

I think the outer set of " has no effect because 
the $(...) business runs normally within them. 

the $( ... ) treats the contents of the group as 
a command line, runs the command in a sub-shell, 
then treats the output (that which the command 
returns to STDOUT) as a command. this is the new, 
modern way of doing `echo ls`, where the backticks 
run the command and treat the returned output of 
the command as a command itself (this case runs 
the echo command, which returns ls to STDOUT, 
and then runs ls as a command). 
   the example case tries to run the tim command 
with arguments = and xxx and can't find the tim 
command; it then tries to run the return, which 
is nothing, and complains that it can't find the 
non-existent command. 

i just like doing this and happily blabber on, 
but i hope this example shows you how to test 
small parts of your program. the formula is to 
write a little bit then run it to ensure that 
little bit works as you hope. add a little bit 
more and run that. fix as you go, add more until 
   in this case, clyde's got it right: 

$ if [ "tim" = "xxx" ] ; then 
> echo fooey 
> fi 

$ if [ "tim" = "tim" ] ; then 
> echo gooey 
> fi

*  if  # gets the 0 (true) or 1 (false) of the 
*  test string comparison  # i.e. [ is the test program, 
   which takes four arguments, the first string, the = 
   operator character, the second string, and the final 
   ] end-of-list character. 
*  after the test, whatever was returned to the if 
   construct controls the command block that follows 
   the then keyword up to the first fi keyword. 

On Tue, 2008-04-29 at 05:13 -0700, Clyde Jones wrote:
> On Mon, Apr 28, 2008 at 8:07 PM, Timothy Wang <timothyjwang at yahoo.com> wrote:
> > I am doing an assignment in City College CS160b and was having difficulty
> >  understanding why it is not working. The assignment is posted on
> >
> >  http://fog.ccsf.cc.ca.us/~gboyd/
> >
> >  under cs 160b asmt02
> Sorry, sent the previous message before I was actually ready - I wish
> I could blame the cat for my being fumble fingered.
> >     if "$("name" = "???")"; then
> The quoting in this line is incorrect.  I believe it should be
> something like this
> >     if [ "$name" = "???" ] ; then

More information about the sf-lug mailing list