sh - Shell script cut returning empty string -


i writing script trying linux distribution. have following code returning empty string. sure missing something

os=`cat /etc/os-release | grep -sw name` newos=$os | `cut -d \" -f2`  echo $newos  

like honesty's answer says, have 2 problems. adding answer, i'd address use of backticks in code.

the command substitution can done in 2 ways 1 using $(command) , other `command`. both work same, $(command) form modern way , has more clarity , readability.

the real advantage of $(...) not readability (that's matter of taste, i'd say), ability nest command substitutions without escaping, , not have worry additionally having escape $ , \ instances. - mklement0

the following code uses modern way:

#!/bin/bash  os=$(cat /etc/os-release | grep -sw name)  newos=$(echo "$os" | cut -d \" -f2)  echo $os echo $newos 

output on computer:

name="ubuntu" ubuntu 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -