0

I was going through a project and I saw there are two scripts:

one runs in bash and other in csh.

Is there any way to merge both the files and run as a single script and one file only, means after merging there should not be the earlier files? This reduce the code size, and will be more user-friendly.

For example:

#!/bin/sh

setenv PROJ_ROOT $PWD
setenv PROJ_OS freebsd
setenv OS freebsd

#!/bin/csh
export ICP=`pwd`

#both /sh
if `uname -r | grep -c "10.2-RELEASE"` == 1 setenv PROJ_WITHOUT_THREAD 1
2
  • To start with the if statement at the end is syntactically wrong. Not sure what you're trying to accomplish here. Could you rephrase the question to make it clearer? Commented Aug 10, 2016 at 14:42
  • The last 'if' checks for the OS version, that if its 10.2-Release, set that variable, that's it. I don't think anything more is needed to clarify. Commented Aug 10, 2016 at 15:02

1 Answer 1

1

Your example script doesn't make sense either way; a shell script cannot set variables in its parent process.

For a superficial compatibility hack, you could declare a function setenv; then most of your example script will run in sh.

setenv () {
    "$1"=$2
    export "$1"
}

Your if clause I believe will be a syntax error in both shells. I can't think of a way to write it portably, but my recommendation would be to abandon csh anyhow.

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

1 Comment

I know it doesn't make any sense but situation comes, I asked a possibility which can add to my knowledge. :)

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.