0

I have bash script

#!/bin/sh

export DEBIAN_FRONTEND=noninteractive;

apt-get update;
apt-get -y upgrade;

apt-get install -y python-pip python-dev nginx;

##After the command output shows visible commands after + sign in bash
set -x -e 

pip install virtualenv;
virtualenv /home/user/virtualenv;
source /home/user/virtualenv/bin/activate;

pip install gunicorn;

systemctl start gunicorn;
systemctl restart nginx;

The Output of command show like

+ virtualenv /home/user/virtualenv
New python executable in /home/user/virtualenv/bin/python
Installing setuptools, pip, wheel...done.
+ source /home/user/virtualenv/bin/activate
++ deactivate nondestructive
++ unset -f pydoc
++ '[' -z '' ']'
++ '[' -z '' ']'
++ '[' -n /bin/bash ']'
++ hash -r
++ '[' -z '' ']'
++ unset VIRTUAL_ENV
++ '[' '!' nondestructive = nondestructive ']'
++ VIRTUAL_ENV=/home/user/virtualenv
++ export VIRTUAL_ENV
++ _OLD_VIRTUAL_PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
++ PATH=/var/www/html/askbotenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
++ export PATH
++ '[' -z '' ']'
++ '[' -z '' ']'
++ _OLD_VIRTUAL_PS1=
++ '[' x '!=' x ']'
+++ basename /home/user/virtualenv
++ PS1='(askbotenv) '
++ export PS1
++ alias pydoc
++ '[' -n /bin/bash ']'
++ hash -r
+ pip install gunicorn
Collecting gunicorn

I want to remove those + sign before the command due to set -x -e

  • Use parentheses to start subshells. – Satō Katsura Jan 29 '17 at 16:49
  • (What makes you think set -x -e enters a sub-process?) – thrig Jan 29 '17 at 16:49
  • 2
    So remove -x ...? – Jeff Schaller Jan 29 '17 at 17:16
  • @jeff-schaller Thanks a lot it helps me lot Regards :) – Gopal Raha Jan 29 '17 at 17:31
2

The set -x -e command will turn on tracing with the -x (this is what produces the + prompts in the output) and will also make the script exit directly if anything goes wrong with the -e.

Having the script exit directly at an error my still be a good thing though, so I'd suggest changing the line to only say

set -e

Alternatively, since the trace is outputted to the standard error stream, you may instead redirect that to /dev/null when running the script:

$ ./myscript 2>/dev/null

... but this would also discard any other diagnostic message that you might actually want to see.

  • It works for me 101% thanks a lot.. :) – Gopal Raha Jan 29 '17 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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