Tag: Bash
TASKNAME=${1:-abc}
$0 | コマンド名 |
$1 | 1つ目の引数 |
$2 | 2つ目の引数 |
$* | 残りの引数全部 |
$# | 引数の個数 |
a="XYZ" echo "$a" echo "${a}"
LANG="hoge"
var="a b c" str=${var:-"d e f"} echo $str str=${var2:-"d e f"} echo $str
a b c d e f
arg1=${1:-"xxx"} echo $arg1
if [ str="a b c d e" if [ "$str" = "a b c" -o "$str" = "a b c d" ]; then echo ok else echo ng fi
str=$1 if [ "$str" = "" ]; then echo "empty" else echo "not empty" fi
if [ -f $file ]; then echo "$file is file." else echo "$file is not file." fi
if [ ! -f $file ]; then echo "$file is not file." else echo "$file is file." fi
exit 0 exit 1
echo "ok"else
echo "ng"fi
function test() { str=$1 echo "$str" } test a
function check() { str=$1 if [ "$str" = "" ]; then echo "empty" else echo "not empty" fi } echo "\$0=$0" check $0 echo "\$1=$1" check $1 echo "\$2=$2" check $2
$0=./param.sh not empty $1= empty $2= empty
argv=("$@")
calling_function() { variable="a" array=( "x", "y", "z" ) called_function "${variable}" "${array[@]}" } called_function() { local_variable="${1}" shift local_array=("${@}") }
# read .bashrc if [ -f ~/.bashrc ]; then . ~/.bashrc fi
export BASE_DIR=$(cd $(dirname $0);pwd)
#!/bin/sh -x set -x
case ${OSTYPE} in darwin*) #ここにMac向けの設定 ;; linux*) #ここにLinux向けの設定 ;; esac
function check() { str=$1 if [ "$str" = "" ]; then echo "引数なし" else echo "引数あり" fi }
#!/bin/sh ruby test.rb $@
ruby test.rb "$@"
#!/usr/bin/env bash if [ "$@" != "" ];then echo "$@" else echo empty fi
"$1" "$2" "$3"