🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.shell
7 messages
7 total messages Started by Calvin Goodrich Wed, 07 Nov 1990 23:00
csh question (and ksh port maybe)
#1726
Author: Calvin Goodrich
Date: Wed, 07 Nov 1990 23:00
16 lines
1020 bytes
can any of you unix.gods tell me what :e :h :t :r :q :x :gh :gt :gr
stand for in csh? i've seen these used before but couldn't figure them out.
for the rtfm'ers in the crowd: yes, i read the man pages on csh but couldn't
get an informative answer.

next question: do these things have an equivalent in ksh? apparently ksh
doesn't have these little buggers. if they're useful i want to be able to
use them in my favorite (imho, anyway) shell.

first person to give me a good answer to both questions gets a free cup of
coffee at my company's cafeteria.  :]


thanx guys,

calvin.
Re: csh question (and ksh port maybe)
#1736
Author: Kevin E. Minor (+1 708 632 7043)
Date: Thu, 08 Nov 1990 15:27
41 lines
2149 bytes
calvin@sequent.sequent.com (Calvin Goodrich) writes:

|>can any of you unix.gods tell me what :e :h :t :r :q :x :gh :gt :gr
|>stand for in csh? i've seen these used before but couldn't figure them out.
|>for the rtfm'ers in the crowd: yes, i read the man pages on csh but couldn't
|>get an informative answer.

OK this is out of my little UNIX pocket handbook back when I was at school
so if it's out of date or something... Sorry.

Argument modifiers (follow argument selectors):
:h	Leave only the head of a pathname.
:r	Remove the extension of a pathname, leaving the root.
:e	Leave only the extension part of a pathname.
:t	Leave the tail of a pathname, removing leading components.
	(My favorite since I use it in my prompt - i.e. $cwd:t)
:g[shret&]	Repeat action of modifier globally.
:q	Quote substituted words to prevent further substitution.
:x	Like (q), but break into words at blanks, tabs, newlines.

And here are the remainder modifiers - even though you didn't ask for them.
:s/<l>/<r>/	Substitute string <r> for string <l>.
:&	Repeat previous expression.
:p	Print but do not execute.

|>next question: do these things have an equivalent in ksh? apparently ksh
|>doesn't have these little buggers. if they're useful i want to be able to
|>use them in my favorite (imho, anyway) shell.

Do know, I try to stay away from ksh... (Just my preference...)

|>first person to give me a good answer to both questions gets a free cup of
|>coffee at my company's cafeteria.  :]

Will ya fly me in too ????  :-)

Kevin
-- 
	/-------------------------------------------------------\
	|	Kevin Minor	...uunet!motcid!minor		|
	\-------------------------------------------------------/
Re: csh question (and ksh port maybe)
#1731
Author: Jonathan I. Kamens
Date: Thu, 08 Nov 1990 21:47
42 lines
2709 bytes
In article <45969@sequent.UUCP>, calvin@sequent.sequent.com (Calvin Goodrich) writes:
|> can any of you unix.gods tell me what :e :h :t :r :q :x :gh :gt :gr
|> stand for in csh? i've seen these used before but couldn't figure them out.
|> for the rtfm'ers in the crowd: yes, i read the man pages on csh but couldn't
|> get an informative answer.

  Then you must have an emasculated version of the csh man page, because mine
documents them as follows:

     After the optional word
     designator can be placed a sequence of modifiers, each pre-
     ceded by a `:'.  The following modifiers are defined:

          h      Remove a trailing pathname component, leaving the head.
          r      Remove a trailing `.xxx' component, leaving the root name.
          e      Remove all but the extension `.xxx' part.
          s/l/r/ Substitute l for r
          t      Remove all leading pathname components, leaving the tail.
          &      Repeat the previous substitution.
          g      Apply the change globally, prefixing the above, e.g. `g&'.
          p      Print the new command but do not execute it.
          q      Quote the substituted words, preventing further substitutions.
          x      Like q, but break into words at blanks, tabs and newlines.

If your csh man page doesn't have this, I suggest you get a new csh man page. 
If it does, then what exactly about it do you not understand?

|> next question: do these things have an equivalent in ksh? apparently ksh
|> doesn't have these little buggers. if they're useful i want to be able to
|> use them in my favorite (imho, anyway) shell.

  I don't use ksh, but from a quick look at the ksh man page, I don't see
anything that can do what all of the modifiers above do.  Some of them can be
done by calling a subprocess such as sed or awk; others can probably be done
using clever quoting, and still others can probably be done with ksh commands
that I'd know about if I used ksh regularly :-).

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710
Re: csh question (and ksh port maybe)
#1756
Author: Matt Day
Date: Fri, 09 Nov 1990 19:32
40 lines
2295 bytes
In article <45969@sequent.UUCP> calvin@sequent.sequent.com (Calvin Goodrich) writes:
>can any of you unix.gods tell me what :e :h :t :r :q :x :gh :gt :gr
>stand for in csh? i've seen these used before but couldn't figure them out.
>for the rtfm'ers in the crowd: yes, i read the man pages on csh but couldn't
>get an informative answer.

Here's a little set of examples (note: I use the tcsh; I don't think the
tcsh and the csh behave differently here, but they might):

> set tmp="/usr/tmp/foo.bar.howdy"
> echo $tmp:e     # (extension) Returns the text to the right of the last '.'
bar
> echo $tmp:h     # (head) Returns the "head" of the path
/usr/tmp
> echo $tmp:t     # (tail) Returns the "tail" (or basename) of the path
foo.bar.howdy
> echo $tmp:r     # (root) Returns everything except for the last '.' extension
/usr/tmp/foo.bar

The :q and :x modifiers are means of setting the high bit on the variable
contents.  :x will set the high bit on all the text in the string except for
spaces and tabs, and :q will set the high bit on everything.  I can't see
very many practical uses for this feature.

As for the :gh, :gt, and :gr modifiers, they seem to do weird things on
my copy of tcsh.  Perhaps they're broken, perhaps I just don't understand
what their purpose is.  In any case, I don't know what they really do.
I think the 'g' means "global" somehow, but I can't tell right off.

Anyway, that ought to get you started.  Those modifiers are really handy,
I use them all the time.  Saves lots of typing, and in shell scripts, they
save a call to "sed".

>next question: do these things have an equivalent in ksh? apparently ksh
>doesn't have these little buggers. if they're useful i want to be able to
>use them in my favorite (imho, anyway) shell.

Sorry, I don't know about the ksh.
-- 
- Matt Day, Sanyo/Icon, mday@iconsys.icon.com || uunet!iconsys!mday
Re: csh question (and ksh port maybe)
#1750
Author: karl_kleinpaste
Date: Fri, 09 Nov 1990 21:10
37 lines
2247 bytes
calvin@sequent.sequent.com writes:
   can any of you unix.gods tell me what :e :h :t :r :q :x :gh :gt :gr
   stand for in csh? i've seen these used before but couldn't figure them out.
   for the rtfm'ers in the crowd: yes, i read the man pages on csh but couldn't
   get an informative answer.

Um, RTFM.

A SunOS 4.1 csh(1) man page discusses exactly what these terms mean on
pages 5 and 9.  Same thing for Pyramid OSx 4.4c's csh(1) man page.
From the Pyr version:

(page 5)
     The `:' separating the event specification from the word
     designator can be omitted if the argument selector begins
     with a `|', `$', `*' `-' or `%'.  After the optional word
     designator can be placed a sequence of modifiers, each pre-
     ceded by a `:'.  The following modifiers are defined:

          h      Remove a trailing pathname component, leaving the head.
          r      Remove a trailing `.xxx' component, leaving the root name.
          e      Remove all but the extension `.xxx' part.
          s/l/r/ Substitute l for r
          t      Remove all leading pathname components, leaving the tail.
          &      Repeat the previous substitution.
          g      Apply the change globally, prefixing the above, e.g. `g&'.
          p      Print the new command but do not execute it.
          q      Quote the substituted words, preventing further substitutions.          x      Like q, but break into words at blanks, tabs and newlines.

(page 9)
     The modifiers `:h', `:t', `:r', `:q' and `:x' may be applied
     to the substitutions above as may `:gh', `:gt' and `:gr'.
     If braces `{' '}' appear in the command form then the modif-
     iers must appear within the braces.  The current implementa-
     tion allows only one `:' modifier on each `$' expansion.

--karl
Re: csh question (and ksh port maybe)
#1742
Author: Alan M. Carroll
Date: Fri, 09 Nov 1990 22:43
19 lines
1520 bytes
In article <45969@sequent.UUCP>, calvin@sequent.sequent.com (Calvin Goodrich) writes:
>  :e :h :t :r :q :x :gh :gt :gr
>  in csh? 
> 
> next question: do these things have an equivalent in ksh?

No. However, ksh shell has much more powerful mechanisms for doing the equivalent
thing. You can enable a 1 line VI editing mode in ksh using
set -o vi
which then allows you to use standard vi editing commands to modify the
command line (press ESCAPE to enter editing mode). I find this far easier to
use then trying to remember which csh : operator is the right one. Also, you
can regexp search your history (!) and repeat the search (just like vi) if
the first one you find isn't what you wanted. This makes searching for the last
command that referenced file "bob" easy.
-- 
Alan M. Carroll                Barbara/Marilyn in '92 :
Epoch Development Team          + This time, why not choose the better halves?
CS Grad / U of Ill @ Urbana    ...{ucbvax,pur-ee,convex}!cs.uiuc.edu!carroll
Re: csh question (and ksh port maybe)
#1759
Author: Stefan Linnemann
Date: Mon, 12 Nov 1990 14:56
62 lines
3056 bytes
In <45969@sequent.UUCP> calvin@sequent.sequent.com (Calvin Goodrich) writes:

>can any of you unix.gods tell me what :e :h :t :r :q :x :gh :gt :gr
>stand for in csh? i've seen these used before but couldn't figure them out.
>for the rtfm'ers in the crowd: yes, i read the man pages on csh but couldn't
>get an informative answer.

Since I'm not (yet) a god, I will not answer.  Would be a bit pointless,
too, after the excellent answers already sent. :-)

>next question: do these things have an equivalent in ksh? apparently ksh
>doesn't have these little buggers. if they're useful i want to be able to
>use them in my favorite (imho, anyway) shell.

Part of their capabilities are implemented in the ksh(1) as follows:
(From the ksh(1) manual page)

     ${parameter#pattern}
     ${parameter##pattern}
	  If the Shell pattern matches the beginning of	the value
	  of parameter,	then the value of this substitution is
	  the value of the parameter with the matched portion
	  deleted; otherwise the value of this parameter is sub-
	  stituted.  In	the first form the smallest matching pat-
	  tern is deleted and in the second form the largest
	  matching pattern is deleted.

     ${parameter%pattern}
     ${parameter%%pattern}
	  If the Shell pattern matches the end of the value of
	  parameter, then the value of this substitution is the
	  value	of the parameter with the matched part deleted;
	  otherwise substitute the value of parameter.	In the
	  first	form the smallest matching pattern is deleted and
	  in the second	form the largest matching pattern is
	  deleted.  In the above, word is not evaluated	unless it
	  is to	be used	as the substituted string, so that, in
	  the following	example, pwd is	executed only if d is not
	  set or is null:
	  echo ${d:-$(pwd)}

>first person to give me a good answer to both questions gets a free cup of
>coffee at my company's cafeteria.  :]

With the airline ticket attached, this would be an even more expensive
cup of coffee, than for the guy from Illenois. :-)

>thanx guys,

>calvin.

You're welcome.
Stefan.

+---------                                                  ---------+
| Stefan M. Linnemann, a.k.a. crissl@rulcvx.LeidenUniv.nl            |
|                                                                    |
  Life is like the odd bit of string: it should be long enough to do  
  Something Extremely Useful with it, but for all of the really neat  
| things we think of, it's just too short.                           |
| -- Me, 1990, as far as I know; correct me if I'm wrong.            |
+---------                                                  ---------+
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads