|
|
#1 |
|
Triple-A Player
Join Date: Jan 2002
Posts: 92
|
tcsh and quotes
Hi,
I'm adding custom aliases to my .tcshrc file, and I have a question... I got a sample file from a friend, and some of the alias stings are set off with single quotes (') and some with double quotes (")... For example: alias blah 'blah blah blah' or alias blab "blabbity blabbity" He said there was a reason for using one over the other under different circumstances, but didn't know why... So, what's the answer? It does seem to make a difference in certain cases, but not in others. For example, my alias for opening the system prefs is as follows: alias prefs "open -a /Applications/System\ Preferences.app" I had previously tried it with single quotes, but I couldn't get it to 'source.' When I typed: source .tcshrc It gave me: Unmatched '. But when I comment it out or use double quotes, all is fine. Other alises for starting apps don't behave this way. Why? Thanks, --jmb |
|
|
|
|
|
#2 |
|
Triple-A Player
Join Date: Jan 2002
Location: Toronto, Canada
Posts: 185
|
Single quote: no interpolation; double quotes interpolation
With double quotes, variables are interpolated (replaced with their values). With single quotes, they are not.
If you define alias test1 "echo $youwin$" This will fail telling you that $youwin is not a variable because it is enclosed in double quotes. It might be what you want to say though: you might really want to define echo $youwin$. You have to define it this way: alias test1 'echo $youwin$' so that anything prefixed by a dollars $ is not mistaken for a variable. |
|
|
|
|
|
#3 |
|
League Commissioner
Join Date: Jan 2002
Posts: 5,536
|
navajo, thanks for the great explanation.
so single quotes are always a literal string of characters, passed thru the shell processing unaltered. & double quotes are a literal string (?) that the shell will scan and interpolate shelly things? there's more to it than that, i believe, because there are other shell quoting chars, but that's a starter. |
|
|
|
|
|
#4 |
|
All Star
Join Date: Jan 2002
Posts: 534
|
I'm looking for a little clarification on special quoting circumstances, specifically this alias I would like to create although the single quote doesn't work and neither does double quote or back tics:
alias frsrc 'find . -type f | sed 's/^/"/;s/$/\/rsrc"/' | xargs ls -l' This is in a tcsh shell with Jag 10.2.1 and will find resource fork files in the cwd. Does anyone know if there is another way to get it working without changing the guts of the line too much? Muchly appreciated in advance. |
|
|
|
|
|
#5 | |||||||||||||||||||
|
Major Leaguer
Join Date: Oct 2002
Posts: 268
|
Re: Reviving this old thread for a moment...
The problem is the quotes for sed. As soon as you hit the ' after sed, you've closed the quote that started just before find, leaving find . -type f | sed not an overly useful command. Any time you need to use literal ' (and possibly the double quotes ") inside a quoted alias, backslash escape them (' -> \', " -> \")... alias frsrc 'find . -type f | sed \'s/^/\"/;s/$/\/rsrc\"/\' | xargs ls -l' Again, you may or may not need to escape the double quotes so try it both ways. HTH Eric |
|||||||||||||||||||
|
|
|
|
|
#6 |
|
Major Leaguer
Join Date: Oct 2002
Posts: 268
|
Sheesh... what is with this board and disappearing backslashes?!?! Let's try this again (and learn to use preview more often
)alias frsrc 'find . -type f | sed \'s/^/\"/;s/$/\/rsrc\"/\' | xargs ls -l' Again, you may or may not need to escape the double quotes... Eric |
|
|
|
|
|
#7 |
|
All Star
Join Date: Jan 2002
Posts: 534
|
ericw13, thanks for the reply. What you said makes perfect sense and I had tried the escapes to no avail both ways. I'm still getting the illegal variable name message from the shell. Can you suggest anything else? TIA.
Just to be clearer, here are what I've tried... alias frsrc 'find . -type f | sed \'s/^/"/;s/$/\/rsrc"/\' | xargs ls -l' alias frsrc 'find . -type f | sed \'s/^/\"/;s/$/\/rsrc\"/\' | xargs ls -l' alias frsrc "find . -type f | sed 's/^/\"/;s/$/\/rsrc\"/' | xargs ls -l" alias frsrc "find . -type f | sed \'s/^/\"/;s/$/\/rsrc\"/\' | xargs ls -l"
Last edited by thatch; 10-27-2002 at 01:45 AM. |
|
|
|
|
|
#8 |
|
Major Leaguer
Join Date: Oct 2002
Posts: 268
|
I'm not much up on sed (preferring to use perl for pattern matching...), but this is what I used to create the alias (this is bash, so slightly different syntax for setting aliases):
alias frsrc='find . -type f | sed "s/^/\"/;s/$/\/rsrc\"/" | xargs ls -l' Not entirely sure what the sed part actually does though. From your original post, you said you want to limit the search to cwd. If so, you should add -maxdepth 0 to the find command. This will prevent find from traversing down the directory structure. Note the differences: the sed commands are delimited with ", not '. The literal " inside sed are backslash escaped. HTH Eric |
|
|
|
|
|
#9 | |||||||||||||||||||
|
All Star
Join Date: Jan 2002
Posts: 534
|
ericw13, thanks again for your reply. I'm chalking this one up to the wonkiness of tcsh. It appears that other shells work fine as you have shown.
Actually, my original post just stated that the line finds resource files in the cwd, which it does do quite nicely without the aliasing in tcsh. The sed line just filters down any filename beginning in anything and ending in rsrc and pipes it on to xargs. |
|||||||||||||||||||
|
|
|
|
|
#10 |
|
League Commissioner
Join Date: Jan 2002
Posts: 5,536
|
another ding against the C-shell family...
% man csh ... After the input line is aliased and parsed, and before each command is executed, variable substitution is performed keyed by `$' characters. This expansion can be prevented by preceding the `$' with a `\\' except within `"'s where it always occurs, and within `''s where it never occurs. Strings quoted by ``' are interpreted later (see Command substitution below) so `$' substitution does not occur there until later, if at all. A `$' is passed unchanged if followed by a blank, tab, or end-of-line. ... from UNIX Power Tools: ... you can't quote things reasonably well in csh. dollar signs ($) cannot be escaped in double quotes in csh. ugh % set foo = "this is a \$dollar quoted and this is $HOME not quoted" dollar: Undefined variable. ... thatch, i suggest you craft that find into a sh script. for filtering out the chaff, i've had luck with this incantation... Code:
$ find . -type f | sed 's/^/"/;s/$/\/rsrc"/' | xargs ls -l | \
awk '{if ($5 > 0 ) print $0 }'
Last edited by mervTormel; 10-28-2002 at 04:09 PM. |
|
|
|
|
|
#11 |
|
All Star
Join Date: Jan 2002
Posts: 534
|
mT, thanks. The sh script in ~/bin with the name frsrc works excellent. And the addition of the awk line leaves out all the zero byte files. Perfect!
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|