-1

After execution of the command

$ cd onos
$ cat << EOF >> ~/.bash_profile
export ONOS_ROOT="`pwd`"
source $ONOS_ROOT/tools/dev/bash_profile
EOF
$ . ~/.bash_profile

I am getting an error

bash: /tools/dev/bash_profile: No such file or directory
bash: pwd/tools/dev/bash_profile: No such file or directory
bash: pwd/tools/dev/bash_profile: No such file or directory
bash: pwd/tools/dev/bash_profile: No such file or directory
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: /tools/dev/bash_profile: No such file or directory
bash: source: /bin/pwd: cannot execute binary file
bash: source: /bin/pwd: cannot execute binary file
bash: pwd/tools/dev/bash_profile: No such file or directory
bash: source: /bin/pwd: cannot execute binary file

The content of ~/.bash_profile is

export ONOS_ROOT="pwd"
source /tools/dev/bash_profile
export ONOS_ROOT="pwd"
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT="pwd"
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT="pwd"
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source /tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source  pwd /tools/dev/bash_profile
export ONOS_ROOT="pwd"
source $ONOS_ROOT/tools/dev/bash_profile
export ONOS_ROOT=" pwd "
source $ONOS_ROOT/tools/dev/bash_profile
  • You should probably delete the extraneous contents of ~/.bash_profile. – dsstorefile1 Aug 1 '18 at 5:08
2

This edit to your .bash_profile is incorrect, because the $ONOS_ROOT variable is expanded by your here-document (<<EOF), so it's not kept verbatim, which I believe is what you wanted:

$ cd onos
$ cat << EOF >> ~/.bash_profile
export ONOS_ROOT="`pwd`"
source $ONOS_ROOT/tools/dev/bash_profile
EOF

The variable is most likely empty, so it expands to nothing, which explains the source /tools/dev/bash_profile line you have in your .bash_profile after running this command.

My recommendation is to use something like this instead:

$ cd onos
$ { echo "export ONOS_ROOT=`pwd`";
    echo 'source $ONOS_ROOT/tools/dev/bash_profile'; } >>~/.bash_profile

Which uses two separate echos, the first using double quotes in order to expand the pwd command output, the second using single quotes to prevent expanding the $ONOS_ROOT variable reference you want to preserve.

This command will still append lines more than once, if you run it repeatedly. So, perhaps, you want to add a check of whether the edit was already performed, in which case you would skip appending:

$ cd onos
$ grep -qw ONOS_ROOT ~/.bash_profile || {
    echo "export ONOS_ROOT=`pwd`";
    echo 'source $ONOS_ROOT/tools/dev/bash_profile';
  } >>~/.bash_profile

Also, this command:

$ . ~/.bash_profile

It can cause issues as well, since .bash_profile is typically supposed to be sourced only once... You're likely to end up with spurious repeated entries in your $PATH at least, which might cause unexpected issues... Best would be to log out and log in again, or to start a new terminal session (assuming your terminal spawns login shells) to have these new settings take effect.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.