[tcsh] $argv loses quotes, messes argument grouping up
[tcsh] $argv loses quotes, messes argument grouping up
am 14.01.2008 19:04:53 von jazzman
Hi, I'm having a problem with a simple tcsh script I'm trying to write.
The script should pass the arguments it received from the command line
to the command it invokes (i.e.: vim).
The problem is that when vim receives the script's arguments, they
aren't quoted/escaped as they originally were on the command line, so
they're not grouped and interpreted correctly.
Here's the script:
-----BEGIN SCRIPT-----
#! /bin/tcsh -f
#
# NAME
# svi - calls vim with the -X option if you're on a VGA console
#
if ( `fgconsole` < 7 ) then
exec vim -X $argv
else
exec vim $argv
endif
------END SCRIPT------
Now, if I call the script this way:
~> svi -c 'set textwidth=72' mytextfile.txt
vim gets called like this:
vim -c set textwidth=72 mytextfile.txt
The result is that vim "thinks" I want execute the "set" command without
an argument, and then edit two files, one called "textwidth=72" and one
called "mytextfile.txt".
Is there a way to pass arguments quoted and grouped as originally
intended?
TIA!
--
..: Jazzman :.
Re: [tcsh] $argv loses quotes, messes argument grouping up
am 14.01.2008 19:14:43 von Stephane CHAZELAS
On Mon, 14 Jan 2008 19:04:53 +0100, Jazzman wrote:
> Hi, I'm having a problem with a simple tcsh script I'm trying to write.
>
> The script should pass the arguments it received from the command line
> to the command it invokes (i.e.: vim).
[...]
I beleive that with tcsh you must use $argv:q
#! /usr/bin/tcsh -f
exec vim $argv:q
tcsh is not recommended for scripting.
-----BEGIN SCRIPT-----
if [ "$(fgconsole)" -lt 7 ]; then
exec vim -X "$@"
else
exec vim "$@"
fi
------END SCRIPT------
--
Stephane
Re: [tcsh] $argv loses quotes, messes argument grouping up
am 14.01.2008 19:19:37 von cfajohnson
On 2008-01-14, Jazzman wrote:
>
> Hi, I'm having a problem with a simple tcsh script I'm trying to write.
>
> The script should pass the arguments it received from the command line
> to the command it invokes (i.e.: vim).
>
> The problem is that when vim receives the script's arguments, they
> aren't quoted/escaped as they originally were on the command line, so
> they're not grouped and interpreted correctly.
>
> Here's the script:
>
> -----BEGIN SCRIPT-----
> #! /bin/tcsh -f
> #
> # NAME
> # svi - calls vim with the -X option if you're on a VGA console
> #
> if ( `fgconsole` < 7 ) then
> exec vim -X $argv
> else
> exec vim $argv
> endif
> ------END SCRIPT------
>
> Now, if I call the script this way:
>
> ~> svi -c 'set textwidth=72' mytextfile.txt
>
> vim gets called like this:
>
> vim -c set textwidth=72 mytextfile.txt
>
> The result is that vim "thinks" I want execute the "set" command without
> an argument, and then edit two files, one called "textwidth=72" and one
> called "mytextfile.txt".
>
> Is there a way to pass arguments quoted and grouped as originally
> intended?
Use a Bourne-type shell for scripts:
if [ `fgconsole` -lt 7 ]
then
exec vim -X "$@"
else
exec vim "$@"
endif
--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Re: [tcsh] $argv loses quotes, messes argument grouping up
am 14.01.2008 19:22:00 von jazzman
Stephane Chazelas dixit:
> I beleive that with tcsh you must use $argv:q
Thanks, Stephane: works like a charm! If only TFM was clearer...
--
..: Jazzman :.
Re: [tcsh] $argv loses quotes, messes argument grouping up
am 14.01.2008 19:25:49 von jazzman
Chris F.A. Johnson dixit:
> Use a Bourne-type shell for scripts:
Thanks Chris, but I like tcsh better!
--
..: Jazzman :.
Re: [tcsh] $argv loses quotes, messes argument grouping up
am 15.01.2008 09:37:31 von gazelle
In article ,
Jazzman wrote:
>Chris F.A. Johnson dixit:
>
>> Use a Bourne-type shell for scripts:
>
>
>Thanks Chris, but I like tcsh better!
>
>
>--
>.: Jazzman :.
Indeed. Basically, if you post a [t]csh question here, the amusement
comes from sitting back, waiting, and counting the number of responses
until someone gives a BS (and off-topic) answer of "Don't use csh. Use
Bourne. Use POSIX. etc, etc".
Fun to be had.