CiCa
CiCa

Reputation: 151

Is it possible to pass a variable to a command inside ` `

I was hoping someone on here can advise...

I was wondering is it possible to pass a variable to a command inside back ticks, like the lufslist command shown below:

#!/bin/bash

    while active_now
        do
              if [ $active_now == no ]
              then
                 while read zonename
                 do
                       ...

                 done < <(`lufslist $be_name`)
              fi
        done < <(lustatus | sed '1,3d' | awk '{print $3}')

I think/hope I'm reasonably close with my above attempt and maybe I'm just missing quotes or brackets of some sort?

Thanks in advance

Upvotes: 0

Views: 241

Answers (1)

fedorqui
fedorqui

Reputation: 290465

Yes! You can use:

while read zonename
do
...
done < <(lufslist "$be_name")

Note the difference between yours

done < <(`lufslist $be_name`)

and

done < <(lufslist "$be_name")

the () makes the command to be executed in a subshell, so you do not have to use the ` character to call it.

Also, it is always good to call your variables enclosed in double quotes: lufslist "$be_name".

Example

$ info="1 month ago"
$ while read a; do echo $a; done < <(date -d"$info")
Wed Sep 18 15:00:59 CEST 2013

Upvotes: 3

Related Questions