From: Melvin on 23 Feb 2010 01:33 Hi, I was trying to compare if the last lline of a file is $end in tcsh. I tried this: ###################### set string1 = `cat file|tail -1` set string2 = "\$end" if (string1 != string2) then echo "Not matching" endif ##################### But shell doesn't allow to compare "$end"[I tries adding the \ to remove the effect of "$" in $end] Error: $end: undefined variable Thanks in Advance Shell Baby
From: David W. Hodgins on 23 Feb 2010 02:01 On Tue, 23 Feb 2010 01:33:34 -0500, Melvin <whereismelvin(a)gmail.com> wrote: > I was trying to compare if the last lline of a file is $end in tcsh. > I tried this: > ###################### > set string1 = `cat file|tail -1` > set string2 = "\$end" > > if (string1 != string2) then I haven't tested it, by try if ("string1" != "string2") then Basic rule. Unless you have a reason not to, always double quote all variables. Regards, Dave Hodgins -- Change nomail.afraid.org to ody.ca to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.)
From: Melvin on 23 Feb 2010 02:19 Hi Dave, I tried wih the double qoutes; but still the same error [end: undefined variable] Is there anyway that the keyword interpretation for $end can by bypassed...Guess somehow "\" is not being taken? Thanks Shell Baby
From: Melvin on 23 Feb 2010 02:31 Hi, The undefined Variable problem is solved. Sln: set string2 = "\$\end" But now string2 assignment results in an error "VARIABLE NAME MUST CONTAIN ALPHANUMERIC CHARACTERS" Any Suggestions
From: Barry Margolin on 23 Feb 2010 03:33 In article <1ebd935b-81be-47b7-ad73-382e15a22f5b(a)z19g2000yqk.googlegroups.com>, Melvin <whereismelvin(a)gmail.com> wrote: > Hi, > > I was trying to compare if the last lline of a file is $end in tcsh. > > I tried this: > ###################### > set string1 = `cat file|tail -1` > set string2 = "\$end" > > if (string1 != string2) then > echo "Not matching" > endif > ##################### > > But shell doesn't allow to compare "$end"[I tries adding the \ to > remove the effect of "$" in $end] > Error: $end: undefined variable > > Thanks in Advance > Shell Baby Use single quotes instead of double quotes, and then it won't try to expand variables: set string2 = '$end' Also, the if statement should be: if ( "$string1" != "$string2" ) then Variables aren't expanded if you don't use the $ prefix. -- Barry Margolin, barmar(a)alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***
|
Next
|
Last
Pages: 1 2 Prev: How to merge these two files? Next: what's the difference between cc and gcc |