Skip to content

Shell Script

Chetabahana edited this page Apr 7, 2019 · 47 revisions

Berikut ini kita akan ulas tentang otomatisasi dalam Shell Script dengan Regular expression

Table of Contents

Shell Script

Script

#!/bin/sh
 if [ -d /home/chetabahana/.docker/backend ]; then
 	cd /home/chetabahana/.docker/backend && docker-compose down --volumes
 	cd .. && sudo rm -rf /home/chetabahana/.docker/backend
 fi
 gcloud source repos clone github_chetabahana_backend backend
 cd /home/chetabahana/.docker/backend/scripts && chmod +x main.sh && ./main.sh

Cloud Build

Biaya Cloud Build untuk build-menit yang dikonsumsi di atas ambang batas tertentu.

Dockerfile

#gcloud builds submit --tag gcr.io/[PROJECT_ID]/init .
FROM alpine
COPY init.sh /
CMD ["/init.sh"]

Cloud Build

#gcloud builds submit --config cloudbuild.yaml .
steps:
- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/init', '.' ]
images:
- 'gcr.io/$PROJECT_ID/init'

Regular expression

Pattern

Sed

sed 's/ [ ]* / /g'
\_/  | \____/ | |
 |   |    |   | \- g=globally (not just one occurence)
 |   |    |   |
 |   |    |   \- to
 |   |    |
 |   |    \- from
 |   |
 |   \- s=substitute
 |
 \- program sed


The from part:
/ [ ]* /
| \_/| 
|  | \- repeated 0-infinite times
|  |
|   \- group of characters
|
\- boundary
Contoh
$ echo 'href="{{ grandchild.url }}"' | \
  sed 's|href="{{ grandchild.url }}"|href="/market{{ grandchild.url }}"|g'
href="/market{{ grandchild.url }}"

$ echo 'href="{{ grandchild.url }}"' | \
  sed 's|href="{{ \([a-zA-Z0-9_]*\).url|href="/market{{ \1.url|g'
href="/market{{ grandchild.url }}"

Quote

Project Tutorial

You are on the wiki of our repo

Chetabahana Project

Clone this wiki locally