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
- taking input from user by
read dataUser
-> this line gone take an input from user and store in username and there is no type specify - can write code for case like
case $dataUser in
1) welcome ;;
2) showFiles ;;
3) finish=1 ;;
*) echo "not vaild babeeeeeeeeeee" ;;
esac
-
- -> the star mean than any thing not in the cases gone do this
echo "not vaild babeeeeeeeeeee"
- -> the star mean than any thing not in the cases gone do this
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