샤인의 IT (막 적는) 메모장

[Bash] Variable 본문

Programming/Bash

[Bash] Variable

신샤인 2022. 1. 22. 17:50
반응형

Variable

 

Command Line에서 변수 지정 시

<변수명> = "<값>"

 

스크립트 작성 시 같음.

 

해당 변수를 가져오고 싶을 땐 $(달러) 기호 사용

 

#변수 지정
[root@scriptbox scripts]# SKILL="DevOps"

# $를 사용해야 변수를 출력한다.
[root@scriptbox scripts]# echo $SKILL
DevOps
[root@scriptbox scripts]# echo SKILL
SKILL
[root@scriptbox scripts]# PACKAGE="httpd wget unzip"
[root@scriptbox scripts]# yum -y install $PACKAGE
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.kaist.ac.kr
 * epel: ftp.riken.jp
 * extras: ftp.kaist.ac.kr
 * updates: ftp.kaist.ac.kr
Package httpd-2.4.6-97.el7.centos.2.x86_64 already installed and latest version
Package wget-1.14-18.el7_6.1.x86_64 already installed and latest version
Package unzip-6.0-24.el7_9.x86_64 already installed and latest version
Nothing to do

 

 

변수를 이용하여 WEB 서버 설치 스크립트

 

#Variable Script
[root@scriptbox tmp]# cat /opt/scripts/3.variable_websetup.sh
#!/bin/bash

#Variable
PACKAGE="httpd wget unzip"
SVC="httpd"
URL="https://www.tooplate.com/zip-templates/2124_vertex.zip"
ART_NAME='2124_vertex'
TEMPDIR="/tmp/webfiles"




# Package Install
sudo yum -y install $PACKAGE > /dev/null


# Start httpd
echo "Start httpd"
echo "###################################"
sudo systemctl start $SVC
sudo systemctl enable $SVC


#templete Setup
echo "Templete Setup"
echo "###################################"
mkdir -p $TEMPDIR
cd $TEMPDIR

wget $URL > /dev/null
unzip $ART_NAME.zip > /dev/null

sudo cp -r $ART_NAME/* /var/www/html/


#restart httpd
echo "httpd restart...."
echo "###################################"
sudo systemctl restart $SVC

ls -l /var/www/html

rm -rf /tmp/webfiles
반응형

'Programming > Bash' 카테고리의 다른 글

[Bash] Export Variable  (0) 2022.01.22
[Bash] Quota & Substitution  (0) 2022.01.22
[Bash] Command Line Argument  (0) 2022.01.22
[Bash] 기본 작성 ( + WEB 서버 실행 스크립트)  (0) 2022.01.22
Comments