Home How to set a variable to the output of a command in Bash?
Reply: 0

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

user609
1#
user609 Published in May 21, 2018, 6:41 pm

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?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.655509 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO