Answer the question
In order to leave comments, you need to log in
How to set bash variable?
I have a deployment script, the task is to substitute the value for example deploy.sh prod (prod is set in ENV).
If you do not substitute a value, then the script fulfills the HOST specified in it by default. How to implement it?
#!/bin/bash
HOST=$PROD
DEST="/var/www/agr/data/www/wiki/public/"
tar -cvzf wiki.tar.gz build/
echo 'Archived'
echo 'Coping sourcee'
scp wiki.tar.gz ${HOST}:${DEST}
echo 'Copied'
echo 'Unziping'
ssh ${HOST} "tar -xvf ${DEST}/wiki.tar.gz -C ${DEST}&& rm ${DEST}/wiki.tar.gz && rm -r ${DEST}/wiki/ && mv ${DEST}/build ${DEST}/wiki"
echo 'unziped'
echo Done
Answer the question
In order to leave comments, you need to log in
script (stripped down) deploy.sh
#!/usr/bin/env bash
_HOST="$1"
if ; then
_HOST="host2"
fi
echo "Используемый хост: $_HOST"
$ export prod="host1"
$ deploy.sh $prod
Используемый хост: host1
$ deploy.sh "host1"
Используемый хост: host1
$ deploy.sh
Используемый хост: host2
Something like this:
HOST=$PROD
if
then
HOST = "default host"
fi
HOST = $([ "$PRODx" == "x" ] && echo "default host" || echo "$PROD")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question