How Do I Store a Grep Value in a Variable in Unix?
Contents

How do you store grep value in a variable?

The syntax is:

  1. VAR=`command-name` VAR=”`grep word /path/to/file`” ## or ## VAR=$(command-name) VAR=”$(grep word /path/to/file)” …
  2. echo “Today is $(date)” ## or ## echo “Today is `date`” …
  3. todays=$(date) …
  4. echo “$todays” …
  5. myuser=”$(grep ‘^vivek’ /etc/passwd)” echo “$myuser”

6 янв. 2017 г.

How do you store a value in a variable in UNIX?

To store the output of a command in a variable, you can use the shell command substitution feature in the forms below: variable_name=$(command) variable_name=$(command [option …] arg1 arg2 …) OR variable_name=’command’ variable_name=’command [option …]

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest