3

I need to check the first command line argument to see if it's -cleanup. My code is:

if ( $* != null ) then

if ( "X$argv[$n]" == "X-cleanup" ) then
    echo "its cleanup"

I first check to make sure there is at least 1 argument. n is set to 1 at the beginning of the program. When I try to run my script with -cleanup as an argument I get this error:

if: Malformed file inquiry.

I've tried solutions from the few forum posts I found online but I cannot figure out how to correctly handle the dash. It's a tcsh shell.

1 Answer 1

3

This script snippet worked for me:

set n = 1
echo $argv[$n]
if ( "$argv[$n]" == "-cleanup" ) then
    echo "its cleanup"
endif

When I run tcsh ./test-cleanup.tcsh -cleanup produces the following output:

-cleanup
its cleanup

The problematic piece of code is the following line. When -cleanup was unquoted, it confuses the csh interpreter as a file check.

if ( $* != null ) then

Replace it with this line:

if ( "$*" != "" ) then
Sign up to request clarification or add additional context in comments.

1 Comment

I saw this problem also with a "-run" kind of argv[1]. My solution was different, but addressed the same problem. My solution was to compare this way: ... if ($argv[1]:q == "-run") ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.