function-case

title: "courses/bash-course - function-case.md"

- **fileName**: function-case
- **Created on**: 2024-06-14 14:36:52

function bash

# there is two way in for type functoin
function welcome() {
	echo "welcome"
}
#call function
welcome
welcome2() {
	echo "welcome"
}
welcome2
# call function

case is way for get input from user and check the input and do something


case $dataUser in
    1)  welcome ;;
    2)  showFiles ;;
    3)  finish=1 ;;
    *)  echo "not vaild babeeeeeeeeeee" ;;
  esac

example for case and function

#!/bin/bash
welcome() {
  echo "---------------"
  echo "welcome"
  echo "---------------"
}

showFiles() {
  echo "---------------"
  ls -al
  echo "---------------"
}

finish=0
while [ $finish -ne 1 ]; do
  echo " --- welcome from yossef --- "
  echo " 1- say welcome "
  echo " 2- show files for current dir "
  echo " 3- exits the program "
  read dataUser;
  case $dataUser in
    1)  welcome ;;
    2)  showFiles ;;
    3)  finish=1 ;;
    *)  echo "not vaild babeeeeeeeeeee" ;;
  esac
done

continue:[[]]
before:while-for.md.md