Hello. Noob question no doubt.
I have this simple script that directs the output of a command to a
variable in posix (i'm doing this for a reason). I'd like to then print
the variable, but expect the print to look like the originally expected
output. I suspect somehow Carriage returns and/or linefeeds are lost
when when i set the variable. Here's the script:
#!/usr/bin/sh
vcdiffout=`cvs -d /avmed/cvs diff $1/$2`
count=`print $vcdiffout | wc -l`
if [ $count = 0 ]
then echo NO CVS DIFFERENCE
else
print $vcdiffout
fi
Problem is - that cvs output is sometimes multiple lines, and when it
is the print in the else shows as one line.
Thanks for any help or information.
|
|
0
|
|
|
|
Reply
|
jason450 (43)
|
12/10/2004 4:02:57 PM |
|
jason@cyberpine.com writes:
> Hello. Noob question no doubt.
>
> I have this simple script that directs the output of a command to a
> variable in posix (i'm doing this for a reason). I'd like to then print
> the variable, but expect the print to look like the originally expected
> output. I suspect somehow Carriage returns and/or linefeeds are lost
> when when i set the variable. Here's the script:
>
> #!/usr/bin/sh
> vcdiffout=`cvs -d /avmed/cvs diff $1/$2`
> count=`print $vcdiffout | wc -l`
> if [ $count = 0 ]
> then echo NO CVS DIFFERENCE
> else
> print $vcdiffout
> fi
>
>
> Problem is - that cvs output is sometimes multiple lines, and when it
> is the print in the else shows as one line.
> Thanks for any help or information.
>
You might want to use the feature of cvs diff, mentioned in its man page:
If cvs is successful, it returns a successful status; if
there is an error, it prints an error message and returns a
failure status. The one exception to this is the cvs diff
command. It will return a successful status if it found no
differences, or a failure status if there were differences
or if there was an error.
However, note also the following
Because this behavior provides no
good way to detect errors, in the future it is possible that
cvs diff will be changed to behave like the other cvs com-
mands.
Anyway, you can always redirect the cvs diff output to a file and count the
number of lines there...
HTH, Dragan
--
Dragan Cvetkovic,
To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer
!!! Sender/From address is bogus. Use reply-to one !!!
|
|
0
|
|
|
|
Reply
|
Dragan
|
12/10/2004 4:16:12 PM
|
|
2004-12-10, 08:02(-08), jason@cyberpine.com:
> I have this simple script that directs the output of a command to a
> variable in posix (i'm doing this for a reason). I'd like to then print
> the variable, but expect the print to look like the originally expected
> output. I suspect somehow Carriage returns and/or linefeeds are lost
> when when i set the variable. Here's the script:
>
> #!/usr/bin/sh
> vcdiffout=`cvs -d /avmed/cvs diff $1/$2`
> count=`print $vcdiffout | wc -l`
> if [ $count = 0 ]
> then echo NO CVS DIFFERENCE
> else
> print $vcdiffout
> fi
[...]
Don't assume "print" to be available in "sh". print is a ksh or
zsh builtin function, so that code will only work if your sh is
a ksh (or zsh). printf is the command to use instead.
Your problem is that you forgot to quote your variables.
#! /usr/bin/sh -
vcdiffout=$(cvs -d /avmed/cvs diff "$1/$2")
# beware that trailing empty lines are discarded
# (that shouldn't happen for a cvs diff output though).
count=$(wc -l << EOF
$vcdiffout
EOF
)
if [ "$((count))" -eq 0 ]; then
echo NO CVS DIFFERENCE
else
cat << EOF
$vcdiffout
EOF
But actually, the whole script can be written as:
#! /usr/bin/sh -
cvs -d /avmed/cvs diff "$1/$2" && echo NO CVS DIFFERENCE
--
Stephane
|
|
0
|
|
|
|
Reply
|
Stephane
|
12/10/2004 4:29:32 PM
|
|
Stephane CHAZELAS wrote:
> 2004-12-10, 08:02(-08), jason@cyberpine.com:
>
>>I have this simple script that directs the output of a command to a
>>variable in posix ...
> Don't assume "print" to be available in "sh". print is a ksh or
> zsh builtin function ...
For the record, he did say "... in posix ...", which presumably means in
the posix shell.
--
Henry Townsend
|
|
0
|
|
|
|
Reply
|
Heny
|
12/10/2004 4:41:34 PM
|
|
2004-12-10, 16:41(+00), Heny Townsend:
> Stephane CHAZELAS wrote:
>
>> 2004-12-10, 08:02(-08), jason@cyberpine.com:
>>
>>>I have this simple script that directs the output of a command to a
>>>variable in posix ...
>
>> Don't assume "print" to be available in "sh". print is a ksh or
>> zsh builtin function ...
>
> For the record, he did say "... in posix ...", which presumably means in
> the posix shell.
Yes. And POSIX doesn't specify any print command, but specfifies
a printf command and an echo command (that it recommands not to
use).
Some Unices have a ksh derived shell as their /POSIX/
conformant shell, some haven't (may be a bash, zsh or ash
derived shell).
--
Stephane
|
|
0
|
|
|
|
Reply
|
Stephane
|
12/10/2004 4:53:23 PM
|
|
|
4 Replies
391 Views
(page loaded in 0.061 seconds)
Similiar Articles: find/replace line of code (with carriage return) - comp.soft-sys ...Carriage return in strings - comp.unix.programmer strcmp usage - comp.soft-sys.matlab Find a string in a cell array - comp.soft-sys.matlab Hi All, I am wondering is ... write linebreaks into text file - comp.soft-sys.matlabCarriage return in strings - comp.unix.programmer write linebreaks into text file - comp.soft-sys.matlab... does not know it is intended for a text file and so is going to ... strcmp usage - comp.soft-sys.matlabfind/replace line of code (with carriage return) - comp.soft-sys ... Carriage return in strings - comp.unix.programmer strcmp usage - comp.soft-sys.matlab Find a string in ... Remove special characters from contents of a cell array - comp ...I have a cell array which contains string elements, but embedded in those strings are special characters (like carriage returns) that are messing up s... Capture windows command return code to variable in awk script ...Carriage return in strings - comp.unix.programmer I have this simple script that directs the output of a command to a variable in ... Capture the terminal text - comp ... return multiple outputs for function - comp.soft-sys.matlab ...Carriage return in strings - comp.unix.programmer... vcdiffout fi Problem is - that cvs output is sometimes multiple ... in "sh". print is a ksh or zsh builtin function ... /bin/sh: Local variables in a function ? - comp.unix.solaris ...Carriage return in strings - comp.unix.programmer Don't assume "print" to be available in "sh". print is a ksh or zsh builtin function, so that ... Addint textbox / notes to a document using PdfBox - comp.text.pdf ...Carriage return in strings - comp.unix.programmer Reading TXT file into MSAccess using Line Input? - comp.databases ... that the printer needs for formatting or, adding ... carriage return, newline, and combinations - comp.lang.awk ...AFAIK, \r is carriage return, \n is newline ... handel multiple character string targets, while TRANSLATE ... by enclosing in quotes and suffixing with X. Carriage return is ... Only number input thru scanf() - comp.lang.cAlso i want the scanf() to accept even the carriage return without entering anything. ... Note that this treats the input as a string, even if it is only one character ... carriage returns in text string - Dev Shedcarriage returns in text string- Oracle Development. Visit Dev Shed to discuss carriage returns in text string C# Carriage Return in string - Toolbox for IT GroupsHie Gurus I am building a string that I will eventuallu write to a text file. The string should have a number of lines separated ... 7/23/2012 1:28:43 PM
|