Skip to main content
Active reading.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

How todo I set a variable to the output of a command in Bash?

I have a pretty simple script that is something like the following:

#!/bin/bash VAR1="$1"  MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF 

When I run this script from the command line and pass it the arguments, I am not getting any output. However, when I run the commands contained within the $MOREF variable, I am able to get output.

I would like to know how oneHow can one take the results of a command that needs to be run within a script, save it to a variable, and then output that variable on the screen?

How to set a variable to the output of a command in Bash?

I have a pretty simple script that is something like the following:

#!/bin/bash VAR1="$1"  MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF 

When I run this script from the command line and pass it the arguments, I am not getting any output. However, when I run the commands contained within the $MOREF variable, I am able to get output.

I would like to know how one can take the results of a command that needs to be run within a script, save it to a variable, and then output that variable on the screen?

How do I set a variable to the output of a command in Bash?

I have a pretty simple script that is something like the following:

#!/bin/bash VAR1="$1" MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF 

When I run this script from the command line and pass it the arguments, I am not getting any output. However, when I run the commands contained within the $MOREF variable, I am able to get output.

How can one take the results of a command that needs to be run within a script, save it to a variable, and then output that variable on the screen?

edited tags
Source Link
codeforester
  • 43.8k
  • 21
  • 122
  • 159

How to set a variable to the output fromof a command in Bash?

I have a pretty simple script that is something like the following:

#!/bin/bash VAR1="$1" VAR2="$2"   MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF 

When I run this script from the command line and pass it the arguments, I am not getting any output. However, when I run the commands contained within the $MOREF variable, I am able to get output.

I would like to know how one can take the results of a command that needs to be run within a script, save it to a variable, and then output that variable on the screen?

How to set a variable to the output from a command in Bash?

I have a pretty simple script that is something like the following:

#!/bin/bash VAR1="$1" VAR2="$2"  MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF 

When I run this script from the command line and pass it the arguments, I am not getting any output. However, when I run the commands contained within the $MOREF variable, I am able to get output.

I would like to know how one can take the results of a command that needs to be run within a script, save it to a variable, and then output that variable on the screen?

How to set a variable to the output of a command in Bash?

I have a pretty simple script that is something like the following:

#!/bin/bash VAR1="$1"  MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF 

When I run this script from the command line and pass it the arguments, I am not getting any output. However, when I run the commands contained within the $MOREF variable, I am able to get output.

I would like to know how one can take the results of a command that needs to be run within a script, save it to a variable, and then output that variable on the screen?

deleted 82 characters in body
Source Link
codeforester
  • 43.8k
  • 21
  • 122
  • 159

I am working on a simple scripting project for work that involves the use of Bash. I have a pretty simple script that is something like the following:

#!/bin/bash VAR1="$1" VAR2="$2" MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF 

When I run this script from the command line and pass it the arguments, I am not getting any output. However, when I run the commands contained within the $MOREF variable, I am able to get output. I

I would like to know how one can take the results of a command that needs to be run within a script, save it to a variable, and then output that variable on the screen?

I am working on a simple scripting project for work that involves the use of Bash. I have a pretty simple script that is something like the following:

#!/bin/bash VAR1="$1" VAR2="$2" MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF 

When I run this script from the command line and pass it the arguments, I am not getting any output. However, when I run the commands contained within the $MOREF variable, I am able to get output. I would like to know how one can take the results of a command that needs to be run within a script, save it to a variable, and then output that variable on the screen?

I have a pretty simple script that is something like the following:

#!/bin/bash VAR1="$1" VAR2="$2" MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF 

When I run this script from the command line and pass it the arguments, I am not getting any output. However, when I run the commands contained within the $MOREF variable, I am able to get output.

I would like to know how one can take the results of a command that needs to be run within a script, save it to a variable, and then output that variable on the screen?

edited title
Link
codeforester
  • 43.8k
  • 21
  • 122
  • 159
Loading
deleted 2 characters in body
Source Link
Jahid
  • 22.6k
  • 10
  • 97
  • 114
Loading
Question Protected by CommunityBot
Fix trivial typos
Source Link
Jonathan Leffler
  • 759.5k
  • 145
  • 961
  • 1.3k
Loading
Source Link
John
  • 25.5k
  • 5
  • 27
  • 26
Loading