after I installed Anaconda package on the server, I'm then trying source ~/.bashrc to set env variable, but it raise an error of export: Command not found, my .bashrc file is like this:
# added by Anaconda3 4.2.0 installer
export PATH="/projdata3/info_fil/wangtao/conda/bin:$PATH"
can anyone help? thanks very much!
Since you're using tcsh, not bash, you should edit your .cshrc and add the line:
set path = ( /projdata3/info_fil/wangtao/conda/bin $path )
Then use source .cshrc.
If your shell is .csh please use setenv to export a variable which in bash you would normally do with export
In bash, export My_VARIABLE=/some/location/or/.something/
In csh shell, it would be setenv My_VARIABLE /some/location/or/.something/
If echo $SHELL command is giving /usr/local/bin/tcsh then it means you are working in csh shell.
In csh shell, if you want to set environment variables, the syntax goes like this
setenv <variable_name> <variable_value>
Here is the useful csh commands link for reference
If you want to enter bash shell from csh shell, enter command bash
Then this command will work: export <variable_name>=<variable_value>
Related
So I have this shell script that checks and then concats an environmental variable to /etc/environment, then reloads the file without having to logout/login:
#!/bin/sh
portvar="PORT=5000"
echo $portvar
grep -q $portvar /etc/environment && echo "EV already in" || echo $portvar >> /etc/environment
set -a; source /etc/environment; set +a;
When I run it, I get the error ./test.sh: 5: ./test.sh: source: not found. However, if I run set -a; source /etc/environment; set +a; directly in the terminal it updates the environmental variable just fine. I have no idea what the set command does, I just found it in another stack overflow question.
Any idea why it runs in the terminal directly but not in the .sh file?
Thanks
/bin/sh on your system is likely some shell that isn't bash and doesn't implement the source command. On my Ubuntu 20.04 system /bin/sh is actually dash.
The source command is not defined by POSIX as part of the shell command language nor is it one of the required special built-in utilities. It's a non-standard feature provided by bash. However, the . command, which does the same thing, is specified by POSIX.
So you can use . instead, e.g. . /etc/environment. Or if you want to keep using source, then you need to have your script run by bash or some other shell that supports it, by changing the shebang line to #!/bin/bash.
There is a tool called checkbashisms that can help you find unintentional uses of bash-specific features in your scripts. When run on your script, it flags this:
possible bashism in foo.sh line 5 (should be '.', not 'source'):
I am trying to use a few perl modules which are located in my own directory.
I read that I need to add the "export" command in this form -
export PERL5LIB=PERL5LIB:/location/of/personal/modules
However I was doing this in bash, and once I tried to source bash after the modification I started to get the "if: Expression Syntax" error.
This tells me that it means my shell is not bash. I queried by echo $SHELL, which gives me tcsh ( I guess its the C shell)
I opened tcsh with the intention of adding the "export" command as written above, however its completely blank and I am now confused as to how to add the non standard directory to #INC.
Any help is greatly appreciated
I think the equivalent tcsh expression is
setenv PERL5LIB PERL5LIB:/location/of/personal/modules
Though I expect that line was supposed to be
export PERL5LIB=$PERL5LIB:/location/of/personal/modules
which would mean you want
setenv PERL5LIB $PERL5LIB:/location/of/personal/modules
But if you don't have anything in the PERL5LIB variable already then you can just use
setenv PERL5LIB /location/of/personal/modules
I develop a Tcl/Tk script tool in Linux. In order to run the tool, every time I need to set the environment variable like this in shell:
setenv LD_LIBRARY_PATH /opt/lsf/9.1/linux2.6-glibc2.3-x86_64/lib:/abc/software/new_2015/GE/tcl_tk/lib64:/abc/software/new_2015/GE/tcl_tk/lib64
and then use "wish" interpreter to launch my tool:
/abc/software/new2015/GE/tcl_tk/bin/wish mytool.tk
To make it a little easy to use, I want design a shell script "abc_wish" and put the above command inside:
#!/bin/sh
setenv LD_LIBRARY_PATH /opt/lsf/9.1/linux2.6-glibc2.3-x86_64/lib:/abc/software/new_2015/GE/tcl_tk/lib64:/abc/software/new_2015/GE/tcl_tk/lib64
wish="/abc/software/new2015/GE/tcl_tk/bin/wish"
exec $wish $#
And then I need just run:
./abc_wish mytool.tk
But error message shows that setenv command not found!I am totally new to such system issues, need some help about these stuffs. Hope I have shown the issue clearly.
setenv is a csh command, not a sh command. The equivalent in bash is export:
#!/bin/sh
export LD_LIBRARY_PATH=/opt/lsf/9.1/linux2.6-glibc2.3-x86_64/lib:/abc/software/new_2015/GE/tcl_tk/lib64:/abc/software/new_2015/GE/tcl_tk/lib64
exec wish "$#"
You should also put $# in quote, to ensure proper re-quoting of the expansion.
in .cshrc file under linux, i have
set path=(/usr/local/gams/24.2.2 $path ) #GAMS DIRECTORY (SOCL)
set path=(/usr/local/bin $path)
set path=(/usr/local/cplex/v12.4/cplex/bin/x86-64_sles10_4.1 $path)
and when i run command source .cshrc i receive this error
-bash: .cshrc: line 1: syntax error near unexpected token `('
-bash: .cshrc: line 1: `set path=(/usr/local/gams/24.2.2 $path ) #GAMS DIRECTORY'
any help?
I am new to linux, so if i made an obvious mistake asking this question, sorry about that
thanks a lot
It seems that you were using bash, not csh family shells. When you ran command source .cshrc, it used bash way to process .cshrc; .cshrc is just the input file, regardless of its file name, so you need to either run csh family shells or use bash syntax for the instructions in .cshrc. (I wouldn't suggest the later way, as it could be confusing.) If you would like to stick with bash, you should do this in .bash_profile or .bashrc.
.cshrc is for the C-shell, not the bash shell. bash uses .bashrc.
I don't know about the c-shell, but in the bash shell, you'd set the PATH variable like this:
PATH="/usr/local/gams/24.2.2:/usr/local/bin:/usr/local/cplex/v12.4/cplex/bin/x86-64_sles10_4.1:$path"
Try echo $PATH first to see if any of those paths (particularly /usr/local/bin) are already in it.
In linux I would go:
setenv -p MYVAR "somevalue"
But this doesn't seem to work in cygwin.
By default Cygwin is running the Bourne shell or Bash, so the command to set a variable is different. This is the code you need:
export MYVAR="somevalue"
The export part lets the shell know that it is an environment variable instead of a local variable.
If you type ls -a in your home directory, you should see some or all of the following files:
.bashrc
.bash_profile
.profile
.bash_profile is executed for login shells, and .bashrc is executed for interactive non-login shells. To most simply ensure that your environment variable is always set, open up .bash_profile and add the text:
export MYVAR="somevalue"
Your shell with then execute .bash_profile every time it starts up, and it will run this command. You will then have the MYVAR variable accessible all of the time. If you didn't export the variable, it would only be accessible within your .bash_profile file.
You can check that this variable is defined by printing its value to your shell:
echo $MYVAR
You can delete (unset) the variable with:
unset $MYVAR
Brief words on shell config files
As an aside, regarding .bashrc vs .bash_profile vs. .profile, see these answers:
difference between .bash_profile and .bashrc
difference between .profile and .bash_profile
For simplicity of configuration, I recommend sourcing your .bashrc file from .bash_profile. Add this to .bash_profile:
if [ -f ${HOME}/.bashrc ]; then
source ${HOME}/.bashrc
fi
This will load .bashrc from .bash_profile.
If you do this, you can instead put the following line in .bashrc, if you wish:
export MYVAR="somevalue"
The best way to set up environment variables in cygwin is to create a bash profile and execute that profile everytime you login and run the shell.
In my .bash_profile file , this is the setting I have
JAVA_HOME = C:/Program Files/Java/jdk1.7.0_51
export JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin
Once you run bash, check out echo $JAVA_HOME and you should see the path as output.