Shell Script

1 min read

Return value in bash script

echo 사용 :

function fun1(){
  echo 34
}

function fun2(){
  local res=$(fun1)
  echo $res
}

$(...) captures the text sent to stdout by the command contained within

return 사용 :

function fun1(){
  return 34
}

function fun2(){
  fun1
  local res=$?
  echo $res
}

$? contains the result code of the last command.

© 2023 Raegon Kim