Tag: Bash
TASKNAME=${1:-default unknown_task}
$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
function test() { str=$1 echo "$str" } test a
argv=("$@")
calling_function() { variable="a" array=( "x", "y", "z" ) called_function "${variable}" "${array[@]}" } called_function() { local_variable="${1}" shift local_array=("${@}") }
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"