[ShellScript] 기초 템플릿

2023. 2. 28. 17:35Developers 공간 [Shorts]/Software Basic

728x90
반응형
<분류>
A. 수단
- OS/Platform/Tool : Linux, Kubernetes(k8s), Docker, AWS
- Package Manager : node.js, yarn, brew, 
- Compiler/Transpillar : React, Nvcc, gcc/g++, Babel, Flutter

- Module Bundler  : React, Webpack, Parcel

B. 언어
- C/C++, python, Javacsript, Typescript, Go-Lang, CUDA, Dart, HTML/CSS

C. 라이브러리 및 프레임워크 및 SDK
- OpenCV, OpenCL, FastAPI, PyTorch, Tensorflow, Nsight

 


1. What? (현상)

Shell Script 기초 템플릿이 필요합니다.


2. Why? (원인)

  • 하기에 미리 만들어 놓고자 합니다.

3. How? (해결책)

  • shell.sh
#/bin/bash

# USAGE : shell.sh -user A

export PARAMETER="mode1"

export PARAMETER4=false
PARAMETER_LIST=("A", "B", "C", "D")

if [ $# -eq 0 ]
then
    echo "Usage: ./shell.sh [options]"
    echo " "
    echo "options:"
    echo "-h, --help    show brief help"
    echo "-user         show user"
    exit 0
fi

while test $# -gt 0; do
    case "$1" in
        -h|--help)
            echo "Usage: ./shell.sh [options]"
            echo " "
            echo "options:"
            echo "-user         show user"
            exit 0
            ;;
        -user)
            export PARAMETER2="$2"
            shift
            shift
            ;;
        *)
            break
            ;;
    esac
done

case "$PARAMETER" in 
    "mode1")
        export PARAMETER3="TKAY_A100_TEMP_B000_000/abc"
        export PARAMETER4=true
        ;;
    *)
        echo "mode not supported1."
        exit 0
        ;;
esac

SAVE_IFS=$IFS
case "$PARAMETER" in
    "mode1")
        if $PARAMETER4; then
            if [[ $PARAMETER3 == TKAY_A[0-9][0-9][0-9]_*_B[0-9][0-9][0-9]_[0-9][0-9][0-9]/* ]]; then
                IFS='/' 
                read -a vStr <<< $PARAMETER3 # Saparate with /
                IFS='_'
                read -a vStr2 <<< "${vStr[0]}" # Saparate with _
                IFS=$SAVE_IFS
                NAME="${vStr2[0]}"
                VERSION="${vStr2[1]//A}"
                PARAMETER5="${NAME}+${VERSION}";
            elif [[ $PARAMETER3 == TKOY_A[0-9][0-9][0-9]_*_M[0-9][0-9][0-9]_[0-9][0-9][0-9]/* ]]; then
                PARAMETER5="${PARAMETER}/${PARAMETER3}";
            else
                PARAMETER5=" ";
            fi
        else
            echo "param not supported2."
            exit 0
        fi
        ;;
    *)
        echo "mode not supported3."
        exit 0
        ;;
esac

echo "This is $PARAMETER5"
python3 file.py \
    --param5=$PARAMETER5

 

 


 

728x90
반응형