Комментарии:
Enjoying your classes !
ОтветитьThanks for the course.
ОтветитьJust a comment, to promote this great author!
Ответитьhow about passing args to function or getting a return ? Is that explained later ?
Ответитьcool stuff, thanx
Ответить☯🙏
awesome!
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
Ответить👍Nice!
Ответить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.
Ответить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
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.
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.