I have a pretty simple script that is something like the following: 我有一個很是簡單的腳本,以下所示: bash
#!/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. 可是,當我運行$MOREF
變量中包含的命令時,我能夠獲取輸出。 this
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? 如何獲取須要在腳本中運行的命令的結果,將其保存到變量,而後在屏幕上輸出該變量? spa