views:

144

answers:

2

I am new to Linux and I am trying to compile some code that needs environment variables set first. The script is in cshrc, but whenever I try to run that code I get "if: badly formed number" errors. I want to run it in bash instead. Is there an easy way to convert cshrc to bashrc?

A: 

Yes, post the code. There are hordes of alpha geeks just waiting here to do this sort of work for you, sort of like Rent A Coder but without the cost :-)

Seriously, it's likely to be just the fact that, from memory, csh uses parentheses for conditions while bash uses [[...]] but, until you post the code (at least the offending lines with some context), we can't be sure.

In other words, the csh:

if ($number < 0) then
    echo What the ...
endif

would become the bash:

if [[ $number -lt 0 ]] ; then
    echo What the ...
fi
paxdiablo
A: 

If bash is going to be your preferred shell in Linux, rather than looking for a tool, you might be better served to spend a few minutes learning how to do this in bash. Unless the csh script is really complex, it's not likely to take much effort to translate, and having done that you'll be armed with the knowledge to understand future bash (and csh) scripts better.

A couple of tips to get you started:

  • in csh, you set environment variables with setenv; bash uses = + export
  • the if syntax is different between the two

For example:

# bash
if [ ${ORACLE_HOME:-0} = 0 ]; then
    ORACLE_TMP="/tmp"
else
    ORACLE_TMP=$ORACLE_HOME/tmp
fi
export ORACLE_TMP

# csh
if ($?ORACLE_HOME == 0) then
    setenv ORACLE_TMP /tmp  
else                
    setenv ORACLE_TMP $ORACLE_HOME/tmp
endif
David Gelhar