Problems inserting commands in bashrc via script

0

I'm trying to enter commands in bashrc via script.

I run the command

source powerpyenv.sh

# powerpyenv.sh
echo '### Added by pyenv' >> teste
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> teste
echo 'eval "$(pyenv init -)"' >> teste
echo 'eval "$(pyenv virtualenv-init -)"' >> teste

cat << EOF > temp.txt
### Activate virtualenv
alias manage="python $VIRTUAL_ENV/../manage.py"
alias r="manage runserver"
alias sa='source .venv/bin/activate; PS1="('basename \"$VIRTUAL_ENV\"')\e[1;34m:/\W\e[00m$ "; clear'

### Short prompt
alias pa='PS1="('basename \"$VIRTUAL_ENV\"')\e[1;34m:/\W\e[00m$ "; clear'
alias p='PS1="\e[1;34m/\W\e[00m$ "; clear'

alias rm="rm -i"
EOF

cat temp.txt >> teste
rm -f temp.txt

source teste

echo "Done"

I threw everything into a test for now.

See the test result:

### Added by pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
### Activate virtualenv
alias manage="python /../manage.py"
alias r="manage runserver"
alias sa='source .venv/bin/activate; PS1="("")\e[1;34m:/\W\e[00m$ "; clear'

### Short prompt
alias pa='PS1="("")\e[1;34m:/\W\e[00m$ "; clear'
alias p='PS1="\e[1;34m/\W\e[00m$ "; clear'

alias rm="rm -i"

What are the problems here?

  • alias manage was different. You need to see how to enter the $ VIRTUAL_ENV literal.
  • alias sa was different. Both because of $ VIRTUAL_ENV and because of crase and basename.
  • How do I fix this?

        
    asked by anonymous 21.02.2016 / 20:08

    1 answer

    1

    Your cat <<EOF command will use Shell expansion whenever you find subprocess - '', variable - $ , among others. If you want to include them literally in the file is necessary to escape them, for example:

    cat > temp.txt <<EOF
    ### Activate virtualenv
    alias manage="python \$VIRTUAL_ENV/../manage.py"
    ...
    EOF
    
        
    21.02.2016 / 20:59