Bash Scripting for Beginners: Complete Guide to Getting Started - Functions (Part 12)

Bash Scripting for Beginners: Complete Guide to Getting Started - Functions (Part 12)

Learn Linux TV

1 год назад

33,305 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@user-yv5ui9zc7o
@user-yv5ui9zc7o - 24.10.2023 12:52

Enjoying your classes !

Ответить
@soliver111
@soliver111 - 14.08.2023 19:01

Thanks for the course.

Ответить
@sssrgo
@sssrgo - 05.08.2023 17:52

Just a comment, to promote this great author!

Ответить
@mahmoudashraf117
@mahmoudashraf117 - 04.07.2023 13:10

how about passing args to function or getting a return ? Is that explained later ?

Ответить
@antonpanasiuk8225
@antonpanasiuk8225 - 26.05.2023 10:47

cool stuff, thanx

Ответить
@Alpha_Sadigh
@Alpha_Sadigh - 15.05.2023 08:09

☯🙏
awesome!

Ответить
@xaviermalcolm8593
@xaviermalcolm8593 - 29.12.2022 18:55

Hi Jay, thanks for the great tutorial-I'm learning a lot so far; question: in bash does a function always have be declared before its called? Thanks

Ответить
@guilherme5094
@guilherme5094 - 18.12.2022 22:27

👍Nice!

Ответить
@rubberduckey5630
@rubberduckey5630 - 17.12.2022 04:34

When I'm developing comething that is lengthy I will tend to use functions to break it into smaller pieces based on... well function. That way I can find the part that needs attention quicker. Then I just call call each of them at the end while I'm testing, or quickly disable an entire section that is working fine to cut down of the runtime when I go to test a change I made as long as the part I'm working isn't contingent on it.

Ответить
@ibrahimmorketa2093
@ibrahimmorketa2093 - 09.12.2022 09:46

hello sir! it is a nice course. my updater function shows permission denied message for the logfile and errorlog variables.
/usr/local/bin/update: line 16: /var/log/updater.log: Permission denied
An error occurred, please check the /var/log/updater_errors.log file.
/usr/local/bin/update: line 18: /var/log/updater.log: Permission denied
An error occurred, please check the /var/log/updater_errors.log file.
here is my code.

#!/bin/bash

release_file=/etc/os-release
logfile=/var/log/updater.log
errorlog=/var/log/updater_errors.log

check_exit_status() {
if [ $? -ne 0 ]
then
echo "An error occurred, please check the $errorlog file."
fi
}

if grep -q "Ubuntu" $release_file || grep -q "Debian" $release_file
then
sudo apt-get update 1>>$logfile 2>>$errorlog
check_exit_status
sudo apt-get dist-upgrade -y 1>>$logfile 2>>$errorlog
check_exit_status
fi

Ответить
@kangsankim3753
@kangsankim3753 - 05.12.2022 13:33

Thanks for a great tutorial. I have a question.
Is there return value or parameters in bash function?
It seems quite different from function in C language.

Ответить
@AlbusRegis
@AlbusRegis - 29.11.2022 00:08

Bash functions are very powerful while creating scripts but have some limitations:
They can return an exit code with the keyword "return", if you have been following the series you may gess why this is useful.
They will never return a anything that is not an exit code, this means that if you want a function to populate a variable you will have to get creative with data stream redirections.
your_var=$(your_function) achieves most things, but it is not even close to being foolproof.

Ответить