I'm trying to set java path. i am getting an error in .bash_profile. I don't know why. It seems everything good.
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
JAVA_HOME=/apps/erp/java/jdk1.7.0_71
PATH=$PATH:$HOME/bin:$JAVA_HOME:$JAVA_HOME/bin:$JAVA_HOME/lib/dt.jar:
\$JAVA_HOME/lib/tools.jar
export PATH
The problem is probably this here:
PATH=$PATH:$HOME/bin:$JAVA_HOME:$JAVA_HOME/bin:$JAVA_HOME/lib/dt.jar:
\$JAVA_HOME/lib/tools.jar
The continuation backslash should be on the previous line, the line you want to be continued:
PATH=$PATH:$HOME/bin:$JAVA_HOME:$JAVA_HOME/bin:$JAVA_HOME/lib/dt.jar:\
$JAVA_HOME/lib/tools.jar
Or just keep it on a single line:
PATH=$PATH:$HOME/bin:$JAVA_HOME:$JAVA_HOME/bin:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
Related
Even after restarting,as soon as I open terminal on the top I get this
bash: export: `/home/shameen:/usr/bin:/usr/local/bin': not a valid identifier
bash: ./bashrc: No such file or directory
Any idea how can I remove this error?
enter image description here
Without seeing what's actually in your startup/resource files (eg, ~/.bashrc, ~/.profile, ~/.bash_profile, etc) we can only guess.
For the 2nd error message re: ./bashrc, Renaud Pacalet has already addressed this one ... incorrect reference of the bashrc file:
wrong: ./bashrc
right: .bashrc (or ~/.bashrc)
I'm guessing you have something like:
. ./bashrc # or
source ./bashrc
which should be:
. .bashrc # or
source .bashrc # or
. ~/.bashrc # or
source ~/.bashrc
For the 1st error message I'm guessing you've populated a variable (eg, PATH) and incorrectly exported this variable:
wrong: export $PATH # contents of PATH variable are exported
right: export PATH # variable is exported
Example:
$ x='/home/shameen:/usr/bin:/usr/local/bin'
$ export x
$
# no output, just a new prompt; this means the variable was successfully exported
$ export $x
-bash: export: `/home/shameen:/usr/bin:/usr/local/bin': not a valid identifier
# attempt to 'export' the contents of variable 'x' => same error message you're receiving
Here is an excerpt from my Bash script
#!/bin/sh
# Check SPEED parameter validity
if [ "$4" = "SPEED" ]
then
source ${SIM_DIR}/setEnv.sh speed
elif [ "$4" = "NORMAL" ]
then
pushd ${SIM_DIR}/scripts
source setEnv
else
ERROR "Invalid SPEED|NORMAL parameter ($4)."
exit 1
fi
In command line, I am giving the option as NORMAL when I run the script. There is no file called setEnv.sh in the ${SIM_DIR}/scripts location. There is however a file called setEnv and its first line is #!/bin/bash -x. I get the following error:
line 176: source: setEnv: file not found
Could anybody kindly point out what is wrong with my script?
source uses PATH lookups to find names that do not contain slashes, and your PATH (correctly) does not contain ., so the current directory is not searched for setEnv. Use source ./setEnv.
The shebang line is ignored by source.
I'm running a project inside a virtualenv in python. Here's the path to the virtualenv.
~/iss/issp/bin
The problem is when I try to run the activate script with:
source activate
it throws the following error.
:~/iss/issp/bin$ source activate
: command not found
bash: activate: line 4: syntax error near unexpected token `$'{\r''
'ash: activate: line 4: `deactivate () {
Here's the code inside the script:
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
deactivate () {
unset pydoc
# reset old environment variables
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
PATH="$_OLD_VIRTUAL_PATH"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "$_OLD_VIRTUAL_PYTHONHOME" ] ; then
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
hash -r 2>/dev/null
fi
if [ -n "$_OLD_VIRTUAL_PS1" ] ; then
PS1="$_OLD_VIRTUAL_PS1"
export PS1
unset _OLD_VIRTUAL_PS1
fi
unset VIRTUAL_ENV
if [ ! "$1" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}
# unset irrelevant variables
deactivate nondestructive
VIRTUAL_ENV="/home/pablo/issp"
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH
# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "$PYTHONHOME" ] ; then
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
unset PYTHONHOME
fi
if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
_OLD_VIRTUAL_PS1="$PS1"
if [ "x" != x ] ; then
PS1="$PS1"
else
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
else
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
fi
fi
export PS1
fi
alias pydoc="python -m pydoc"
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
hash -r 2>/dev/null
fi
The issue is that the activate script has Windows line endings. We can confirm this by running the below command on the command line.
$ file activate
which returns
activate: ASCII text, with CRLF line terminators
CRLF line terminators means windows line endings.
Therefore we need to convert them to Unix line endings so that we can source the file.
We have a few of options
dos2unix activate - (this edits the file in place)
sed -i 's/\r$//' activate (also edits the file in place)
mv activate activate_with_windows_line_endings && (tr -d '\r' < activate_with_windows_line_endings ) > activate here we we just remove any occurrence of \r and the original file is preserved.
Open the file in your favourite text editor. Most will have a way to both show the current line endings of the file (bottom right of image below) and a way to convert them to Unix line endings (In Notepad++ we go to Edit → EOL Conversion → Unix (LF) and then save. Here is a screenshot of how to do it in Notepad++
Finally
Now source activate should work.
Just had the same problem, and decided to do hexdump -C bin/activate to figure out. Turns out my bin/activate file had CR/LF line endings instead of just CR, changing them with (tr -d '\r' < bin/activate) > bin/activatefixed my problem.
I ran into this problem using VS Code and the venv package from python's standard library, since I use bash for my default terminal.
Bash scripts should always use LF instead of CRLF line endings. This is now fixed for the python virtualenv package, but it's still an issue with venv.
As described here, https://bugs.python.org/issue43437, venv copies its activate script template in binary mode when creating new virtual environments. Therefore we only need to convert the original to Unix line endings, using any of Mark's methods above.
The activate script template is located here: <python3_root>/Lib/venv/scripts/common/activate
To fix it in place: sed -i 's/\r$//' activate
As long as that file keeps its LF line endings, new virtual environments created with venv should have viable activation scripts.
Maybe you have an alias in your .bashrc file, that's why deactivate takes like the command, not like a function
instead
deactivate() {
use this
function deactivate() {
This is the script that I used to that will not run, but I am hoping someone can help me figure out what the issue is. I am new to unix
#!/bin/bash
# cat copyit
# copies files
numofargs=$#
listoffiles=
listofcopy=
# Capture all of the arguments passed to the command, store all of the arguments, except
# for the last (the destination)
while [ "$#" -gt 1 ]
do
listoffiles="$listoffiles $1"
shift
done
destination="$1"
# If there are less than two arguments that are entered, or if there are more than two
# arguments, and the last argument is not a valid directory, then display an
# error message
if [ "$numofargs" -lt 2 -o "$numofargs" -gt 2 -a ! -d "$destination" ]
then
echo "Usage: copyit sourcefile destinationfile"
echo" copyit sourcefile(s) directory"
exit 1
fi
# look at each sourcefile
for fromfile in $listoffiles
do
# see if destination file is a directory
if [ -d "$destination" ]
then
destfile="$destination/`basename $fromfile`"
else
destfile="$destination"
fi
# Add the file to the copy list if the file does not already exist, or it
# the user
# says that the file can be overwritten
if [ -f "$destfile" ]
then
echo "$destfile already exist; overwrite it? (yes/no)? \c"
read ans
if [ "$ans" = yes ]
then
listofcopy="$listofcopy $fromfile"
fi
else
listofcopy="$listofcopy $fromfile"
fi
done
# If there is something to copy - copy it
if [ -n "$listofcopy" ]
then
mv $listofcopy $destination
fi
This is what I got and it seems that the script didn't execute all though I did invoke it. I am hoping that someone can help me
[taniamack#localhost ~]$ chmod 555 tryto.txt
[taniamack#localhost ~]$ tryto.txt
bash: tryto.txt: command not found...
[taniamack#localhost ~]$ ./tryto.txt
./tryto.txt: line 7: $'\r': command not found
./tryto.txt: line 11: $'\r': command not found
./tryto.txt: line 16: $'\r': command not found
./tryto.txt: line 43: syntax error near unexpected token `$'do\r''
'/tryto.txt: line 43: `do
Looks like your file contains Windows new line formatting: "\r\n". On Unix, a new line is just "\n". You can use dos2unix (apt-get install dos2unix), to convert your files.
Also have a look at the chmod manual (man chmod).
Most of the time i just use chmod +x ./my_file to give execution rights
I see a few issues. First of all, a mode of 555 means that no one can write to the file. You probably want chmod 755. Second of all, you need to add the current directory to your $PATH variable. In Windows, you also have a %PATH%, but by default the current directory . is always in %PATH%, but in Unix, adding the current directory is highly discouraged because of security concerns. The standard is to put your scripts under the $HOME/bin directory and make that directory the last entry in your $PATH.
First of all: Indent correctly. When you enter a loop or an if statement, indent the lines by four characters (that's the standard). It makes it much easier to read your program.
Another issue is your line endings. It looks like some of the lines have a Windows line ending on them while most others have a Unix/Linux/Mac line ending. Windows ends each line with two characters - Carriage Return and Linefeed while Unix/Linux/Mac end each line with just a Linefeed. The \r is used to represent the Carriage Return character. Use a program editor like vim or gedit. A good program editor will make sure that your line endings are consistent and correct.
I have a script which redirects std out/std err as below:
SCRIPTS=/test/scripts
LOG=/test/log
echo $SCRIPTS
echo $LOG
$SCRIPTS/dmm_algo_ofac_daily_sched.ksh >> $LOG/test12.log 2>&1
This script is not able to expand $SCRIPTS and $LOG
If I replace it as below:
/test/scripts/daily_sched.ksh >> /test/log/test12.log 2>&1
It complains as below:
: bad file unit numberd/test.ksh: line 33: 1
Also I am not able to invoke the script from the directory where it is saved. If I do
./test.ksh it gives me error saying file not found. I am able to execute it via ksh /test/sched/test.ksh though.
Can someone help me with these. Thanks in advance.
I'm almost certain that the problem is because of DOS/Windows line endings
The error message you are getting is overwriting itself because of a carriage return. You can fix your file using dos2unix.
Add magic #!/bin/ksh to the first line to invoke directly without naming the interpreter on the command line.
I'll conjecture wildly that your root cause(s) has (have) nothing to do with redirection.
Is the script you've exhibited /test/sched/test.ksh or /test/scripts/test.ksh? Are you certain?