I need some help understanding this bash script - Ask Ubuntu
i've been googling each parameter etc in script trying understand each line saying (if makes sense). wondered if kind enough me out helping me 'translate' plain english means? i've done first 5 lines i'm not sure if it's correct :/ appreciated. thank you!
this script:
#!/bin/bash current=0 while [ $seconds -le 10 ]; if [ $seconds -eq ${current} ]; echo ${current} current=$((${current}+1)) fi done
the magic of built-in bash variable $seconds
your script highlights built-in bash variable $seconds
keeps track of how many seconds bash script has been running. starts @ 0 , working variable current
set value @ beginning of script. script loops , increments current
each time $seconds changes , displays "1, 2, 3... 10" on screen.
analyzing bash script line line:
#!/bin/bash
tells system bash script
current=0
sets variable current 0
while [ $seconds -le 10 ]; do
when number of seconds script has been running less or equal 10 following
if [ $seconds -eq ${current} ]; then
if value of current equal number of seconds then:
echo ${current}
display current value (0 initially, 1, 2, 3... 10)
current=$((${current}+1))
increment current value
fi
end of if statement, required syntax rules
done
end of while loop, required syntax rules
testing script
to test script copy , paste op's text new file. our purposes call file seconds
. mark file executable command:
chmod +x seconds
then call bash script current directory prefix in front:
./seconds
Comments
Post a Comment