Shell Script Help (C-Shell Script)

Shell Script Help (C-Shell Script)

Post by mogref » Sat, 20 Oct 2001 18:05:00



In my class we had to write a C program and now we have to write a shell
script to do the exact same thing. I am not sure where to get started using
tr and sed to accomplish this assignment. Here is the assignmnet...

--------------------------------------------------------------
(1) remove all non-printing characters (character codes 1 through 31,
   and 127) and replace them with the same sort of codes the vi
   editor uses.  For example, the bell character (character code 7)
   is replaced by the two printable characters "^" and "G" (G is the seventh
   letter of the alphabet).  Appendix I of Foster lists the ASCII character
   set, and it shows all the proper two-character sequences that should
   be used for the non-printing characters.  There are two special cases:
   Replace the delete character by "^?".  Newlines should be replaced by a
   dollar sign ("$") and then an actual newline.
   **you may ignore NUL (character code 0)**

(2) delete all non-ASCII characters (those with character codes 128 through
255).

(3) truncate all output lines that would otherwise extend past column 72.
Begin
   reading the data on the next line after ignoring the rest of the
character past column 72.

Make sure it reads from stdin and prints to stdout.  It should be comprised
of standard UNIX utilities (that is, it should not invoke any specialized C
programs
that you may consider writing). You MUST make use of pipes rather than using
files to store intermediate results.  Don't make this assignment
unnecessarily hard: the whole program can be done in ONE line (not counting
all the documentation lines).
--------------------------------------------------------------

I was thinking that (1) could be accomplished by using a tr line like ( tr
'\001-\011' '\136') but that replaces some of the non printing with the ^,
how would i get the letter in there and would I have to have a bunch of
those tr commands piped together just to accomplish (1)?

Some help on this would really really be appreciated as its due on Monday
and I've hit a brick wall on this one.

-mogrefy

 
 
 

Shell Script Help (C-Shell Script)

Post by Ed Rolis » Sun, 21 Oct 2001 01:42:58



>In my class we had to write a C program and now we have to write a shell
>script to do the exact same thing. I am not sure where to get started using
>tr and sed to accomplish this assignment. Here is the assignmnet...

>--------------------------------------------------------------
>(1) remove all non-printing characters (character codes 1 through 31,
>   and 127) and replace them with the same sort of codes the vi
>   editor uses.  For example, the bell character (character code 7)
>   is replaced by the two printable characters "^" and "G" (G is the seventh
>   letter of the alphabet).  Appendix I of Foster lists the ASCII character
>   set, and it shows all the proper two-character sequences that should
>   be used for the non-printing characters.  There are two special cases:
>   Replace the delete character by "^?".  Newlines should be replaced by a
>   dollar sign ("$") and then an actual newline.
>   **you may ignore NUL (character code 0)**

>(2) delete all non-ASCII characters (those with character codes 128 through
>255).

>(3) truncate all output lines that would otherwise extend past column 72.
>Begin
>   reading the data on the next line after ignoring the rest of the
>character past column 72.

>Make sure it reads from stdin and prints to stdout.  It should be comprised
>of standard UNIX utilities (that is, it should not invoke any specialized C
>programs
>that you may consider writing). You MUST make use of pipes rather than using
>files to store intermediate results.  Don't make this assignment
>unnecessarily hard: the whole program can be done in ONE line (not counting
>all the documentation lines).
>--------------------------------------------------------------

>I was thinking that (1) could be accomplished by using a tr line like ( tr
>'\001-\011' '\136') but that replaces some of the non printing with the ^,
>how would i get the letter in there and would I have to have a bunch of
>those tr commands piped together just to accomplish (1)?

>Some help on this would really really be appreciated as its due on Monday
>and I've hit a brick wall on this one.

cat -v is your friend.

mixed with a little tr or sed to remove 'ASCII' chars.

add a bit of fold to truncate at 72 chars

PS My newsreader yaks on the fact that you managed to crosspost to nonexistant
groups.

 
 
 

Shell Script Help (C-Shell Script)

Post by John Doher » Sun, 21 Oct 2001 02:54:00



> In my class we had to write a C program and now we have to write a shell
> script to do the exact same thing. I am not sure where to get started using
> tr and sed to accomplish this assignment.

Well, you should start by reading the man pages.

 Here is the assignmnet...

Quote:

> --------------------------------------------------------------
> (1) remove all non-printing characters (character codes 1 through 31,
>    and 127) and replace them with the same sort of codes the vi
>    editor uses.  For example, the bell character (character code 7)
>    is replaced by the two printable characters "^" and "G" (G is the seventh
>    letter of the alphabet).  Appendix I of Foster lists the ASCII character
>    set, and it shows all the proper two-character sequences that should
>    be used for the non-printing characters.  There are two special cases:
>    Replace the delete character by "^?".  Newlines should be replaced by a
>    dollar sign ("$") and then an actual newline.
>    **you may ignore NUL (character code 0)**

> (2) delete all non-ASCII characters (those with character codes 128 through
> 255).

> (3) truncate all output lines that would otherwise extend past column 72.
> Begin
>    reading the data on the next line after ignoring the rest of the
> character past column 72.

> Make sure it reads from stdin and prints to stdout.  It should be comprised
> of standard UNIX utilities (that is, it should not invoke any specialized C
> programs
> that you may consider writing). You MUST make use of pipes rather than using
> files to store intermediate results.  Don't make this assignment
> unnecessarily hard: the whole program can be done in ONE line (not counting
> all the documentation lines).
> --------------------------------------------------------------

> I was thinking that (1) could be accomplished by using a tr line like ( tr
> '\001-\011' '\136') but that replaces some of the non printing with the ^,
> how would i get the letter in there and would I have to have a bunch of
> those tr commands piped together just to accomplish (1)?

> Some help on this would really really be appreciated as its due on Monday
> and I've hit a brick wall on this one.

> -mogrefy

 
 
 

Shell Script Help (C-Shell Script)

Post by John W. Krah » Sun, 21 Oct 2001 13:39:11



> In my class we had to write a C program and now we have to write a shell
> script to do the exact same thing. I am not sure where to get started using
> tr and sed to accomplish this assignment. Here is the assignmnet...

> --------------------------------------------------------------
> (1) remove all non-printing characters (character codes 1 through 31,
>    and 127) and replace them with the same sort of codes the vi
>    editor uses.  For example, the bell character (character code 7)
>    is replaced by the two printable characters "^" and "G" (G is the seventh
>    letter of the alphabet).  Appendix I of Foster lists the ASCII character
>    set, and it shows all the proper two-character sequences that should
>    be used for the non-printing characters.  There are two special cases:
>    Replace the delete character by "^?".  Newlines should be replaced by a
>    dollar sign ("$") and then an actual newline.
>    **you may ignore NUL (character code 0)**

> (2) delete all non-ASCII characters (those with character codes 128 through
> 255).

> (3) truncate all output lines that would otherwise extend past column 72.
> Begin
>    reading the data on the next line after ignoring the rest of the
> character past column 72.

> Make sure it reads from stdin and prints to stdout.  It should be comprised
> of standard UNIX utilities (that is, it should not invoke any specialized C
> programs
> that you may consider writing). You MUST make use of pipes rather than using
> files to store intermediate results.  Don't make this assignment
> unnecessarily hard: the whole program can be done in ONE line (not counting
> all the documentation lines).
> --------------------------------------------------------------

> I was thinking that (1) could be accomplished by using a tr line like ( tr
> '\001-\011' '\136') but that replaces some of the non printing with the ^,
> how would i get the letter in there and would I have to have a bunch of
> those tr commands piped together just to accomplish (1)?

> Some help on this would really really be appreciated as its due on Monday
> and I've hit a brick wall on this one.

Well, since you mentioned "script" and "ONE line":

perl -0777pe 'tr/\x80-\xFF//d;
s/([\0-\x09\x0B-\x1F])/"^".chr(ord($1)+64)/eg; s/\x0A/\$\x0A/g;
s/\x7F/^?/g; s/(.{72})/$1\n/mg'

John
--
use Perl;
program
fulfillment

 
 
 

Shell Script Help (C-Shell Script)

Post by Bruce Barnet » Sun, 21 Oct 2001 20:28:05



Quote:> perl -0777pe 'tr/\x80-\xFF//d;
> s/([\0-\x09\x0B-\x1F])/"^".chr(ord($1)+64)/eg; s/\x0A/\$\x0A/g;
> s/\x7F/^?/g; s/(.{72})/$1\n/mg'

Grade: C-

Reason:

Quote:> > You MUST make use of pipes rather than using
> > files to store intermediate results.

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
 
 
 

Shell Script Help (C-Shell Script)

Post by John W. Krah » Mon, 22 Oct 2001 12:28:49




> > perl -0777pe 'tr/\x80-\xFF//d;
> > s/([\0-\x09\x0B-\x1F])/"^".chr(ord($1)+64)/eg; s/\x0A/\$\x0A/g;
> > s/\x7F/^?/g; s/(.{72})/$1\n/mg'

> Grade: C-

> Reason:

> > > You MUST make use of pipes rather than using
> > > files to store intermediate results.

Stick this in any pipe you want and it will work.

John
--
use Perl;
program
fulfillment

 
 
 

Shell Script Help (C-Shell Script)

Post by Bruce Barnet » Mon, 22 Oct 2001 21:32:34



Quote:> Stick this in any pipe you want and it will work.

        | cat

:-)

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.

 
 
 

Shell Script Help (C-Shell Script)

Post by mogref » Tue, 23 Oct 2001 17:27:32


Thanks for the help guys... I've written the script and documented. My prof
has run a few preliminary grades and I found I needed to move the cut to the
end. I am still missing the following in the auto grade output.

tr -d '[\200-\377]' | cat -v | sed 's/$/\$/' | cut -c1-72

Third test... does your script have the proper first line?

#! /bin/csh -f

Yes.

One point was possible here; your total is now 1/1

Fourth test... is your script executable, and does it work?

[1] 21676

Here is the result of ~masc0077/As5/script1 < ~masc0000/data1 :

A diff of the correct output with your output shows:

ERROR ERROR ERROR ERROR

5,6c5,6

< Make sure you don't mangle square brackets ('[' and ']').$

< consecutive tabs^I^I^I(3 of them)$

---

Quote:> Make sure you don't mangle square brackets ('' and '').$
> consecutive tabs (3 of them)$

8c8

< a^Iab^Iabc^Iabcd^Iabcde^Iabcdef^Ix$

---

Quote:> a ab abc abcd abcde abcdef x$

The actual diff command I used was:

/usr/local/bin/diff -a myoutput youroutput

Two points were possible here; your total is now 1/3

Here is the result of feeding script1 a file with 'long' lines: script1 <
~masc0000/data2

A diff of the correct output with your output shows:

No differences encountered -- CONGRATULATIONS

One point was possible here; your total is now 2/4

The result of feeding script1 a file containing non-ASCII characters:
script1 < ~masc0000/data3

A diff of the correct output with your output shows:

No differences encountered -- CONGRATULATIONS

One point was possible here; your total is now 3/5

The result of feeding script1 a file containing control characters: script1
< ~masc0000/data4

A diff of the correct output with your output shows:

No differences encountered -- CONGRATULATIONS

One point was possible here; your total is now 4/6

Checking your calendar info as well:

cat ~masc0077/calendar

9/19 The "calendar" program mailed this near the due date for Assignments 1
& 2 Assignments 1,2,3 should be completed by the evening of September 25
Assignment 4 is due on Sunday, October 7 Assignment 5 is due on Monday,
October 22 (10/22) Our first programming assignment (program1 - p1.c) is due
Sunday, October 28 (10/28) Assignment 6 is due on Friday, November 2 (11/2)
Our final is scheduled for Thursday, December 20 from 1:00 to 3:00pm

Checking for our current October entries...

One point was possible here; your total is now 5/7

THE AUTOGRADER IS ONLY SMART ENOUGH TO FIGURE OUT THE FIRST SEVEN POINTS.
7/7 is the best total it can achieve right now, so: Your actual grade for
this assignment will be determined by a (human) grader at the due date.

------

Total Points | 5+?| for masc0077 -  for Assignment 5

|----|

| 7+6|

------

Assignment 5 gradesheet

a PARTIAL checklist of things the grader may judge:

Autograder output

___/7

Documentation return values investigated?

___/4 name, class, date?

Algorithm and program style deficiencies documented?

___/ NO 'temporary' files,

Program logic and correctness NO 'helper' files,

___/2 etc...

--------

Total Points | |

| ---- |

| 13 |

--------

 
 
 

Shell Script Help (C-Shell Script)

Post by mogref » Wed, 24 Oct 2001 06:53:14


HAHA... I kind of wanna send that to the professor but he probably wouldn't
like me too much for doing it.


> #
> #   Third test... does your script have the proper first line?
> #
> #   #! /bin/csh -f
> #
> #   Yes.

> Negative 5 points to the professor for
> having you code a shell script in csh.

>     http://www.faqs.org/faqs/unix-faq/shell/csh-whynot

 
 
 

Shell Script Help (C-Shell Script)

Post by David Masterso » Wed, 24 Oct 2001 08:19:31


>>>>> mogrefy  writes:


>> #
>> #   Third test... does your script have the proper first line?
>> #
>> #   #! /bin/csh -f
>> #
>> #   Yes.
>> Negative 5 points to the professor for having you code a shell
>> script in csh.
>> http://www.faqs.org/faqs/unix-faq/shell/csh-whynot
> HAHA... I kind of wanna send that to the professor but he probably
> wouldn't like me too much for doing it.

Tell him it's a joke.  He may read it for a laugh and have an epiphany
about the use of CShell in his class...  ;-)

--
David Masterson                dmaster AT synopsys DOT com
Sr. R&D Engineer               Synopsys, Inc.
Software Engineering           Sunnyvale, CA

 
 
 

Shell Script Help (C-Shell Script)

Post by mogref » Wed, 24 Oct 2001 14:39:55


I have figured out most of the errors except one... the new script code I'm
using is the following...

tr -d '[\200-\377]' | cat -vet | cut -c1-72

Now the only thing not showing up is the [  ] (brackets), anyone know how I
can fix this? Is there another
flag that can be used with cat?

-mogrefy


Quote:> In my class we had to write a C program and now we have to write a shell
> script to do the exact same thing. I am not sure where to get started
using
> tr and sed to accomplish this assignment. Here is the assignmnet...

> --------------------------------------------------------------
> (1) remove all non-printing characters (character codes 1 through 31,
>    and 127) and replace them with the same sort of codes the vi
>    editor uses.  For example, the bell character (character code 7)
>    is replaced by the two printable characters "^" and "G" (G is the
seventh
>    letter of the alphabet).  Appendix I of Foster lists the ASCII
character
>    set, and it shows all the proper two-character sequences that should
>    be used for the non-printing characters.  There are two special cases:
>    Replace the delete character by "^?".  Newlines should be replaced by a
>    dollar sign ("$") and then an actual newline.
>    **you may ignore NUL (character code 0)**

> (2) delete all non-ASCII characters (those with character codes 128
through
> 255).

> (3) truncate all output lines that would otherwise extend past column 72.
> Begin
>    reading the data on the next line after ignoring the rest of the
> character past column 72.

> Make sure it reads from stdin and prints to stdout.  It should be
comprised
> of standard UNIX utilities (that is, it should not invoke any specialized
C
> programs
> that you may consider writing). You MUST make use of pipes rather than
using
> files to store intermediate results.  Don't make this assignment
> unnecessarily hard: the whole program can be done in ONE line (not
counting
> all the documentation lines).
> --------------------------------------------------------------

> I was thinking that (1) could be accomplished by using a tr line like ( tr
> '\001-\011' '\136') but that replaces some of the non printing with the ^,
> how would i get the letter in there and would I have to have a bunch of
> those tr commands piped together just to accomplish (1)?

> Some help on this would really really be appreciated as its due on Monday
> and I've hit a brick wall on this one.

> -mogrefy

 
 
 

Shell Script Help (C-Shell Script)

Post by mogref » Wed, 24 Oct 2001 15:29:43


I figured it out, thanks for all the help guys.

-mogrefy


> I have figured out most of the errors except one... the new script code
I'm
> using is the following...

> tr -d '[\200-\377]' | cat -vet | cut -c1-72

> Now the only thing not showing up is the [  ] (brackets), anyone know how
I
> can fix this? Is there another
> flag that can be used with cat?

> -mogrefy



> > In my class we had to write a C program and now we have to write a shell
> > script to do the exact same thing. I am not sure where to get started
> using
> > tr and sed to accomplish this assignment. Here is the assignmnet...

> > --------------------------------------------------------------
> > (1) remove all non-printing characters (character codes 1 through 31,
> >    and 127) and replace them with the same sort of codes the vi
> >    editor uses.  For example, the bell character (character code 7)
> >    is replaced by the two printable characters "^" and "G" (G is the
> seventh
> >    letter of the alphabet).  Appendix I of Foster lists the ASCII
> character
> >    set, and it shows all the proper two-character sequences that should
> >    be used for the non-printing characters.  There are two special
cases:
> >    Replace the delete character by "^?".  Newlines should be replaced by
a
> >    dollar sign ("$") and then an actual newline.
> >    **you may ignore NUL (character code 0)**

> > (2) delete all non-ASCII characters (those with character codes 128
> through
> > 255).

> > (3) truncate all output lines that would otherwise extend past column
72.
> > Begin
> >    reading the data on the next line after ignoring the rest of the
> > character past column 72.

> > Make sure it reads from stdin and prints to stdout.  It should be
> comprised
> > of standard UNIX utilities (that is, it should not invoke any
specialized
> C
> > programs
> > that you may consider writing). You MUST make use of pipes rather than
> using
> > files to store intermediate results.  Don't make this assignment
> > unnecessarily hard: the whole program can be done in ONE line (not
> counting
> > all the documentation lines).
> > --------------------------------------------------------------

> > I was thinking that (1) could be accomplished by using a tr line like
( tr
> > '\001-\011' '\136') but that replaces some of the non printing with the
^,
> > how would i get the letter in there and would I have to have a bunch of
> > those tr commands piped together just to accomplish (1)?

> > Some help on this would really really be appreciated as its due on
Monday
> > and I've hit a brick wall on this one.

> > -mogrefy

 
 
 

Shell Script Help (C-Shell Script)

Post by mogref » Wed, 24 Oct 2001 15:32:09


I was having a problem with it, it ends up working if I use...

tr -d '\200-\377' | cat -vet | cut -c1-72

basically, I think the [   ]'s inside of the 's deleted the brackets also
along with those non ascii characters. Now everything is working and I
should get 100% as long as my documentation is satisfactory to the prof.

-mogrefy



> #   I have figured out most of the errors except one... the new script
code I'm
> #   using is the following...
> #
> #   tr -d '[\200-\377]' | cat -vet | cut -c1-72
> #
> #   Now the only thing not showing up is the [  ] (brackets), anyone know
how I
> #   can fix this?

> Yeah, don't give use specs to delete those characters,
> which was what you requested, and what the 'tr' does.

> You didn't mean you're having a problem with this, did you?

> boing:root 395> echo '[]' | tr -d '[\200-\377]' | cat -vet | cut -c1-72
> []$

 
 
 

1. c-shell script won't run from korn-shell / SETUID

Greetings,

I have a C program called "tryme" which does a system call
to run a korn-shell script called "trythis.ksh".  This script
calls a C-shell script called "goforit".

My original program "tryme" runs SETUID as user "joe" so
the permissions on "tryme" look like this:

     -rwsr-x---  1 joe   sd   3083 Nov  9  19:06 tryme

The two scripts are executable by everybody.  When I run "tryme"
it calls "trythis.ksh" without problems, but when "trythis.ksh"
then calls the C-shell script "goforit", an error is produced
saying:

    "csh: The file access permissions do not allow the specified
     action."

When I turn off the SETUID permission from tryme and the rerun
it, everything works just fine.  Does anybody know why turning
on SETUID for tryme has an adverse affect on the c-shell script?

-Steve

2. High Speed ethernet

3. a question about executing a shell script (c-shell)

4. REQ: Visual C++ 4.2 or later!

5. handling SIGINT in shell scripts when executing another shell script.

6. VT-220 Emulations Sought...

7. Q: How can I have a shell script call another shell script...

8. RH 7.1 kernel?

9. Shell script invoking other shell scripts

10. Convert Bash shell script to Korn shell script

11. How to pass a variable from a shell script to another shell script...

12. Shell script acting as interactive shell - $0 not script name??

13. shell script within shell script (general question)