3

I saw a similar problem in bash but couldn't solve it for my case. I'm running a simple script:

#!/bin/bash

set mystring=0

if ( "$mystring" == "0" )    
  echo "true"     
elseif    
  echo "wrong"    
endif

my output is "line 12: syntax error: unexpected end of file". Can you help?

0

2 Answers 2

2

Here's a working bash version (rather than tcsh), given the first line in your example:

#!/bin/bash
mystring="0"
if [ "$mystring" -eq "0" ]; then
  echo "true"
else
  echo "wrong"
fi

Note that much of the syntax was slightly incorrect for bash, even though the logic all looked correct. You should also determine if "mystring" is going to be an integer or a string type - here I made the assumption that you're expecting strings, and modified the example accordingly.

Sign up to request clarification or add additional context in comments.

1 Comment

Agree, mix of bash and tcsh. OP, which do you want? Your headline says tcsh. Also any variation of elseif (elif) per the original sample code requires something to test, for example elif [[ -f ${fileToProcess} ]] ; then ...
1

if you are using tcsh then your if syntax is wrong. Use as below

if ( "$mystring" == "0" ) then
commands
else
commands
endif

you might face the issue even after changing this. it can be resolved by sourcing your script instead of just typing its name in the shell. i.e.,

$source script.sh
instead of
$script.sh

Comments

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.