1

I am installing some open source software by compiling its source code -- on Ubuntu 16.04 -- by following the instructions in its 'readme' file. At certain point (point 3b in the link) the guideline requires me to run a .csh file located in a certain directory in order to generate executables. When I execute the required csh script from the terminal in the required directory by typing ./compile_all.csh, or run csh to start an interactive shell, I am met with following line on terminal:

MANPATH: undefined variable. 

Can anyone guide me how can I fix this error?

The following is the result of the manpath command when executed from an Ubuntu terminal:

~$ manpath
/home/atrcheema/share/man:/usr/local/man:/usr/local/share/man:/usr/share/man

The ~./cshrc file contained just one line as seen by execution of following command:

:/home$ vim ~/.cshrc
setenv MANPATH ${MANPATH}:${HOME}/share/man

The first few lines of compile_all.csh are as follows:

#!/bin/csh

####### section added by York Prado 10/2009
if( ! (-e /usr/bin/f77 || -e /bin/f77 || -e /usr/local/bin/f77) ) then 
echo "f77 command is not found"
echo "Please make sure you have the fortran 77 compiler installed"
exit 1
endif 

# section below moved to compile_hspf_libs.csh
#cd hspf/lib3.2/src/util
#make clean 
#make 
#make install 
#cd ../ 
#cd wdm/
#make clean
#make 
#make install
#cd ../
#cd adwdm/
#make clean
##make
#make install
#echo "Compiled all the lib3.2 files needed to compile the CBWM"
#cd ../../../../ 

######### end York Prado section

cd lib/dsn/
f77 -c dsn_utils.f

cd ../util
rm ../util_lib.a
./compile
cd ../get
rm ../get_lib.a
./compile
cd ../tty/
gcc -c -o ../ttyux.o ttyux.c
derHugo
  • 3,306
  • 5
  • 30
  • 49
Ather Cheema
  • 113
  • 1
  • 6
  • If you just need to run a provided `csh` script, then it shouldn't be necessary to start an interactive C-shell - just make sure it's executable and run it as `./somescript`. If you *do* need to get the interactive shell to work for some reason, then check for a `~/.cshrc` or `~/.tcshrc` file and [edit] your question to include its contents – steeldriver Oct 21 '17 at 12:09
  • @steeldriver Edited the question as the error is not related to going in 'interactive shell'. Should I include csh file content as well? – Ather Cheema Oct 21 '17 at 12:19
  • Yes if you have a `~/.cshrc` or `~/.tcshrc` please include it – steeldriver Oct 21 '17 at 12:29
  • @Eliah Kagan Yes the script is same as you mentioned. I am executing the script from terminal. I dont have '~/.cshrc' file in that particular directory. – Ather Cheema Oct 21 '17 at 13:04
  • 1
    The .cshrc file would be in your home directory – John Anderson Oct 21 '17 at 13:08

2 Answers2

2

The error message

MANPATH: undefined variable. 

is because Ubuntu doesn't set MANPATH by default (man has a built-in search path) and csh (unlike Bourne shells) doesn't treat unset variables as empty.

However it should not in itself prevent the shell OR any C-shell script from running.

Nevertheless, if you want to "fix" it, you will need to modify your ~/.cshrc file to check whether MANPATH is set or not and treat the two cases appropriately - something like

if ( ${?MANPATH} ) then 
  setenv MANPATH ${MANPATH}:${HOME}/share/man
else 
  setenv MANPATH ${HOME}/share/man
endif

DISCLAIMER I'm not fluent in csh syntax so YMMV.

derHugo
  • 3,306
  • 5
  • 30
  • 49
steeldriver
  • 131,985
  • 21
  • 239
  • 326
  • I've confirmed that when `MANPATH` is set, the `man` command does *not* use `/etc/manpath.config`. So if `MANPATH` wasn't defined and is then set to `${HOME}/share/man`, that *will* keep `man` from finding the system-provided manpages. Sorry about the back-and-forth (in case you saw my previous comments that I've since deleted). I'll post an answer. Anyway, the most important part of this answer--that you don't usually need the `man` command to work in the shell that runs a script, as most scripts don't use it--is fully correct. *If* the OP's script is failing, it's likely for another reason. – Eliah Kagan Oct 21 '17 at 14:40
  • The script did run after this fix however showed some other compilation errors which are not related to this post. Thanks guys. – Ather Cheema Oct 21 '17 at 14:53
  • 1
    @AtherCheema Note that the important part of this answer for your purposes--that the "undefined variable" error won't hinder compilaton--is correct, but **the method shown here won't give a properly working manpath.** If you want that, see [my answer](https://askubuntu.com/a/967247). If you don't care about it, you can just remove the line that causes the error from `~/.cshrc` (which will actually let the `man` command work for system-provided manual pages). Or if that was the only line in `~/.cshrc`, you can even delete `~/.cshrc`. You can post a new question for help with the new errors. – Eliah Kagan Oct 21 '17 at 14:58
1

Change ${MANPATH}:${HOME}/share/man to"`manpath`:$HOME/share/man".

Your ~/.cshrc file contains (and actually consists entirely of) a command whose intent is to augment the list of directories in which the man command will look for manual pages:

setenv MANPATH ${MANPATH}:${HOME}/share/man

However, that is not a generally correct way to achieve this, and it does not work for your situation, because the MANPATH environment variable does not exist. That's what produces your error message.1

The manpath command, which you found does work, automatically does the right thing. It checks if there is a MANPATH environment variable, and uses it if it exists (and is nonempty). But if there is no such environment variable (or it exists but is blank), manpath consults the configuration file /etc/manpath.config to determine what the default manpath should be, and uses that. When you set the MANPATH environment variable, the entries in that file are no longer automatically used, so you are responsible for ensuring that MANPATH contains them, except in the unusual case that you do not want them.2

Fortunately, this is easy to do, because you can just use command substitution to include the ouptut of the manpath command in the value assigned to the MANPATH variable. Replace the line ~/.cshrc currently contains with this:

setenv MANPATH "`manpath`:$HOME/share/man"

Backticks (` `) perform command substitution in csh and tcsh. In Bourne-style shells like bash, there is also a $( ) syntax for command substitution, which is generally preferable to backticks, but that does not apply to C shells. You can't use the $( ) syntax with csh/tcsh; they don't support it.


1 However, as steeldriver says, you can probably proceed without fixing this problem. Most scripts don't use the man command, though some may. Even if your script installs software that includes manual pages, it will likely not consult the current manpath to figure out where to put them. Of course, if its documentation says it does, then that supersedes this guess. I do suggest you fix this problem, but you can likely proceed without doing so.

2 The man command uses the same procedure to decide where to look for manual pages, possibly by calling manpath. See manpath(5) (man 5 manpath), which says, "If the environment variable $MANPATH is already set, the information contained within /etc/manpath.config will not override it." I have confirmed, by testing, that this is the case. For example, running env MANPATH=. man tcsh from your home directory will say No manual entry for tcsh.

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493