I want a shell script to get current linux distribution name.
There is a command I found : awk '/^ID=/' /etc/*-release | awk -F'=' '{ print tolower($2) }', but it's output is "centos", need remove ".
By learning similar partern from:
https://stackoverflow.com/a/25507646/1637673
https://stackoverflow.com/a/20601998/1637673
I finnally work it out by awk '/^ID=/' /etc/*-release | awk -F'=' '{ gsub(/\"/, "") }1 { print tolower($2) }'.
But I don't understand what does number 1 do in that pattern. Remove 1 would break that command. Read man awk , awk_regular_expressions and others tutorials, none of them mention such a pattern.
Update
I copy Floris's explanation here:
gsub(/^[ \t]+/,"",$2); - starting at the beginning (^) replace all (+ = zero or more, greedy)
consecutive tabs and spaces with an empty string
gsub(/[ \t]+$/,"",$2)} - do the same, but now for all space up to the end of string ($)
1 - ="true". Shorthand for "use default action", which is print $0
- that is, print the entire (modified) line
1 ="true". Shorthand for "use default action", which is print $0
But there is already an action { print tolower($2) } in my script, why need another default action before it?