10
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/my/lib

error:

Bad : modifier in $ (/)

echo $SHELL

/bin/tcsh

I want to add my library to LD_LIBRARY_PATH variable. But Gives the above error.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
elif mutlu
  • 103
  • 1
  • 1
  • 8

2 Answers2

13

As Ignacio Vazquez-Abrams, pointed out you need to set environment variable in tcsh syntax as

setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:"/home/my/lib"
Community
  • 1
  • 1
Inian
  • 80,270
  • 14
  • 142
  • 161
  • 1
    To clarify what's going on here: tcsh allows "variable modifiers" in the form of `$varname:modifier`, so if your variable name is followed by a `:text` you need to use the `${..}` syntax to make it clearer that the `:text` isn't part of the variable modifier. – Martin Tournoij Dec 05 '16 at 14:28
4
# Assign empty string to LD_LIBRARY_PATH, if the variable is undefined
[ ${?LD_LIBRARY_PATH} -eq 0 ] && setenv LD_LIBRARY_PATH ""

setenv LD_LIBRARY_PATH "${LD_LIBRARY_PATH}:/home/my/lib"

Checking if the Variable is Defined

If the variable was not previously defined, the simple setenv LD_LIBRARY_PATH value command will fail with an error like LD_LIBRARY_PATH: Undefined variable.. To prevent this, check the value of ${?LD_LIBRARY_PATH} (substitutes the string 1 if name is set, 0 if it is not) and set a default value as it is shown above.

Using Double Quotes

Also note the use of double quotes. Suppose the variable contains spaces, e.g.:

setenv LD_LIBRARY_PATH "/home/user with spaces/lib"

Then the command without quotes:

setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/home/my/lib

will fail with the following error:

setenv: Too many arguments. 

In double quotes, however, the value is passed to the command as a single word.

Ruslan Osmanov
  • 20,486
  • 7
  • 46
  • 60