Find the answer to your Linux question:
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 ....
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    9

    Question 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 .

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    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.html
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    May 2008
    Posts
    9

    Question Help

    Actually I was not understanding the 3rd line in it i.e.
    uptime=${uptime/./}

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    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:
    Code:
    var=abc
    ${var/a/b} # bbc
    ${var/ab/123} # 123c
    ${var/ac/123} # abc
    ${var/a/} # bc
    So basically, this line:
    Code:
    uptime=${uptime/./}
    means remove the first '.' from $uptime and store that value in $uptime.

    Make sense?
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...