posted by Solver Full-stack Developer 2013.11.26 13:55

Step 1 make ini/properties file


ex) info.properties

name=angela

age=25



Step 2 use ini/proeperties file

ex)profile.sh

. info.properties

echo "name is $name, age is $age"

신고
posted by Solver Full-stack Developer 2013.11.21 15:34

tables=( "auth" "key" "ledger" )

readonly TABLE_COUNT=${#tables[@]}



신고
posted by Solver Full-stack Developer 2013.11.20 14:42

#!/bin/bash

num=10


echo "num is $flag"

echo $((++flag))

echo $((flag+5))

echo $((++flag))

신고
posted by Solver Full-stack Developer 2013.11.20 14:04

#!/bin/bash

mySqlPSCnt=$(pgrep mysqld | wc -l);

if [ "$mySqlPSCnt" == 0 ];

then

        echo "mySQL is down.";

else

        echo "mySQL is alive.";

fi


referebce : https://gist.github.com/mheadd/5571023


신고
posted by Solver Full-stack Developer 2013.11.20 13:40

#!/bin/bash

Result=`mysql -u userId -puserPw --skip-column-names -e "show databases like 'database_name'"`

if [ "$Result" != "database_name" ]; then

    echo "Database isn't exist"

else

    echo "Database is exist"

fi

신고
posted by Solver Full-stack Developer 2013.11.19 16:57

Style one


mysql --user=mysql_user_ID --password=mysql_user_password database_name  << EOF

show tables;





Style two


Result=`mysql -u userId -puserPw --skip-column-names -e "show databases like 'database_name'"`

if [ "$Result" != "database_name" ]; then

    echo "Database isn't exist"

else

    echo "Database is exist"

fi



신고
posted by Solver Full-stack Developer 2013.11.19 14:34

Step 1. add option word:


Step 2. add option case



#!/bin/bash

echo "OPTIND starts at $OPTIND"

while getopts ":p:q:d:" optname

  do

    case "$optname" in

      "p")

        echo "Option $optname is specified"

        ;;

      "q")

        echo "Option $optname has value $OPTARG"

        ;;

      "d")

        echo "Directory is $OPTARG"

        ;;

      "?")

        echo "Unknown option $OPTARG"

        ;;

      ":")

        echo "No argument value for option $OPTARG"

        ;;

      *)

      # Should not occur

        echo "Unknown error while processing options"

        ;;

    esac

    echo "OPTIND is now $OPTIND"

  done


reference : http://www.ibm.com/developerworks/opensource/library/l-bash-parameters/index.html


신고
posted by Solver Full-stack Developer 2013.11.18 11:15

#!/bin/bash

target="Izlovezangelazbaby"


#replace other word

output="${target/z/a}"

#output="${target/z/}"


#replaced stirng echo 

echo $target | sed "s/z/ /g"


echo $output

신고
posted by Solver Full-stack Developer 2013.11.12 14:39

#!/bin/bash


function intro(){

        echo "swap shell script!"

}


function swapNum(){


        local tmp=$1

        num1=$num2 #call by value

        num2=$tmp


        return 255 #return value is 1byte

}


intro


echo "begin num is $1, $2"


num1=$1

num2=$2


swapNum num1 num2 #call fucntion


echo "result is $?"//return value

echo "artificial num is $num1, $num2"



신고