Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: csh (or tcsh) help needed
Date: Thu, 28 Aug 2025 18:46:46 -0700 (PDT)
From: Paul Goyette <paul%whooppee.com@localhost>
Message-ID: <Pine.NEB.4.64.2508281845520.21528%speedy.whooppee.com@localhost>
What Gary said, but:
| alias Q4 'sed -e "s/\$//g"'
The issue with that is that the alias will become
sed -e "s/\$//g"
which isn't legal csh syntax ( $/ is not a proper variable expansion),
and even if it were, wouldn't do what you want.
The quoting needs to retain the \ for sed, and not allow csh to see
the $ as a potential expansion; to do that the easiest way is to have
the alias use single quotes, rather than double.
sed -e 's/\$//g'
which when written as the alias command
alias Q4 "sed -e 's/"'\$'"//g'"
where the \$ always appears inside single quotes so you don't need to
deal with csh's weird "" rules ($ inside "" is always a variable reference,
that can't be prevented by a \, so a literal $ needs to be unquoted \$ or
single quoted).
Or you can do it Gary's way (which I, at least, need to reread several
times to comprehend) where the quotes keep flipping around (it would be
a little easier if it just used \' when it wanted a literal ' rather than "'").
In any case, always work things out in this order, start with the command
that you need to generate, then work out how to encode it in whatever
command (alias in this case, but also when using eval, etc) you need to
embed it in), rather than starting with the command you hope will work,
and then try and massage it into the correct form.
I have never used tcsh, I had abandoned csh long before it appeared, so
I have no idea how to deal with backslash_quote.
kre
ps: you should probably try bash - it is mostly finger compatible with
csh (which is why I switched sometime in the 80's) but being based on
a rational overall design (the Bourne shell syntax) is in general much
easier, and in particular, has functions --- in bash (or any sh variant)
you wouldn't use an alias (even though (simple) aliases exist, there's
really no good reason to use them), so what you'd do there is
Q4() { sed -e 's/\$//g' "$@"; }
which is almost impossible to get wrong. (The "$@" just adds any
args that you give to "Q4" when you use it, the same way an alias would).
Home |
Main Index |
Thread Index |
Old Index