Results 1 to 4 of 4
Can anyone please explain me on what this part of script is doing?
read uptime < /proc/uptime
uptime=${uptime%% [0-9]*}
uptime=${uptime/./}
echo $uptime
Thanks in advance for ur help ....
- 07-03-2008 #1Just Joined!
- Join Date
- May 2008
- Posts
- 9
Shell scripting help
Can anyone please explain me on what this part of script is doing?
read uptime < /proc/uptime
uptime=${uptime%% [0-9]*}
uptime=${uptime/./}
echo $uptime
Thanks in advance for ur help
.
- 07-03-2008 #2
What exactly don't you understand? If it's the middle two lines, I suggest that you read this excellent reference on Bash string manipulation:
http://www.tldp.org/LDP/abs/html/str...ipulation.htmlDISTRO=Arch
Registered Linux User #388732
- 07-04-2008 #3Just Joined!
- Join Date
- May 2008
- Posts
- 9
Help
Actually I was not understanding the 3rd line in it i.e.
uptime=${uptime/./}
- 07-04-2008 #4
Okie dokie. A statement of the form ${variable/substring/replacement} means "Find the first match of substring in variable and replace it with replacement".
So lets see some examples:
So basically, this line:Code:var=abc ${var/a/b} # bbc ${var/ab/123} # 123c ${var/ac/123} # abc ${var/a/} # bc
means remove the first '.' from $uptime and store that value in $uptime.Code:uptime=${uptime/./}
Make sense?DISTRO=Arch
Registered Linux User #388732


Reply With Quote