0

My default shell is bash in Ubuntu 14.04. I have a csh script file named clean.sh with the following make command:

#! /bin/csh -f
make -f commande.make del

And commande.make has

CKHOME=../CHEMKIN/DATA_BASES
LIN_DATA=${CKHOME}/LIN_FILES/
LINK_CKTP=${CKHOME}/LINK_CKTP_FILES/
#-----------------------------------------------------
include schema_cinetique.make
LINKFILE=${NAME}_LINK
LINKTPFILE=${NAME}_LINKTP
LINKFILE_OLD=${NAME_OLD}_LINK
LINKFILE_NEW=${NAME_NEW}_LINK
#-----------------------------------------------------
cplink :    
    ${COPY} ${LINK_CKTP}${LINKFILE} LINK
cplink2 :   
    ${COPY} ${LINK_CKTP}${LINKFILE} LINKZ1
tplink :    
    ${COPY} ${LINK_CKTP}${LINKTPFILE} LINKTPZ1
calcul :
    ${COPY} jobtimp1  LJOBNZ1
    ${COPY} unsteadyf.dat1 DATZ1
del :
    ${DELETE} LINKZ1 LINKTPZ1 LJOBNZ1 DATZ1 SOLASUZ1

I opened the terminal and moved to the location and tried

./clean.sh

or

csh clean.sh & 

or

csh -f clean.sh 

Nothing worked.

I got the following line in the terminal,

LINKZ1 LINKTPZ1 LJOBNZ1 DATZ1 SOLASUZ1
make: LINKZ1: Command not found
make: *** [del] Error 127

So, how to run clean.sh file ?

10
  • What does Nothing worked mean? Can you post the error message? Commented Jan 3, 2022 at 10:59
  • Your script uses commande.make. But your file is named command.make. Commented Jan 3, 2022 at 11:01
  • 1
    @hek2mgl, please check the edited question again with the error Commented Jan 3, 2022 at 11:01
  • 1
    No need to change anything. Just run it as bash clean.sh. You may want to delete/update the initial #! line, if you want. Alternatively, you can also invoke make directly from the command line (why do you use a script, if all what it does is just calling make???) However, I have rather the feeling that something is wrong with the Makefile itself, so this is is unrelated to which shell happens to be used to invoke make. Unfortunately, your posting is incomplete in this respect, so I can't help here much. It seems that the make variable DELETE is empty. Commented Jan 3, 2022 at 11:24
  • 1
    The export is not really necessary if you specify it on the same command line as the make command. That sets the variable only for the duration of the command's execution. The answer actually tries to explain this; maybe read up on what export does if you need a more detailed explanation. Commented Jan 3, 2022 at 11:35

2 Answers 2

4

You are confused. The Csh script contains a single command which actually runs identically in Bash.

#!/bin/bash
make -f commande.make del

Or, for that matter, the same with #!/bin/sh. Or, in this individual case, even sh clean.sh, since the shebang is then just a comment, and the commands in the file are available in sh just as well as in csh.

Once make runs, that is what parses and executes the commands in commande.make. make is not a "Fortran command", it is a utility for building projects (but the makefile named commande.make probably contains some instructions for how to compile Fortran code).

In the general case, Csh and Bash are incompatible, but the differences are in the shell's syntax itself (so, the syntax of loops and conditionals, etc, as well as variable assignments and various other shell builtins).

As an aside, Csh command files should probably not have a .sh extension, as that vaguely implies Bourne shell (sh) syntax. File extensions on Unix are just a hint to human readers, so not technically important; but please don't confuse them/us.

(As a further aside, nobody should be using Csh in 2022. There was a time when the C shell was attractive compared to its competition, but that was on the order of 40 years ago.)

The subsequent errors you are reporting seem to indicate that the makefile depends on some utilities which you have not installed. Figuring that out is a significant enough and separate enough question that you should probably ask a new question about that, probably with more debugging details. But in brief, it seems that make needs to be run with parameters to indicate what NAME and COPY (and probably some other variables) should be. Try with make -f commande.make COPY=cp DELETE=rm NAME=foobar for a start, but it's probably not yet anywhere near sufficient.

(I would actually assume that there will be a README file or similar to actually instruct you how to use commande.make since it seems to have some local conventions of its own.)

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

2 Comments

If you are not getting csh: command not found it actually worked, and the only problem is that you need to figure out how to run the commands in commande.make correctly.
faqs.org/faqs/unix-faq/shell/csh-whynot explains some problems with Csh, and coincidentally provides identical or near-identical sh constructs for many of the problematic behaviors.
1

It seems the script is written having portability in mind, i.e. the name of the cp and rm binaries is kept in variables rather than hard-coding it. My best guess is that this has been done to make it possible to run the script on non UNIX systems, like Windows.

To make it work, export the respective variables before running the script. For the del action you are calling, only the DELETE variable is needed. It should be set to rm which is the command used to remove files on Linux:

export DELETE=rm
./clean.sh

Note: exporting the variable can also be done in one line when invoking the script, by prepending it to the command line:

DELETE=rm ./clean.sh

This behaviour is described in the bash manual:

The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described in Shell Parameters. These assignment statements affect only the environment seen by that command.

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.